- Added new constants P_NAME_REQUEST_ID and

P_NAME_REQUEST_DATA_FORMATTER tp logLib
- Added new properties _requestId and _requestDataFormatter to LogLib
- Added new public method setConfigs to LogLib
- Added possibility to choose the request id when the LogLib is loaded
- Added possibility to format the request data using the
_requestDataFormatter parameter
- Now LogLib always stores the request id + log level
- Added possibility to change the execution time parameter
- Adapted application/core/JOB_Controller.php code
- Adapted application/core/JQW_Controller.php code
This commit is contained in:
Paolo
2020-09-11 17:43:39 +02:00
parent 01a8ec69de
commit fbd4ded720
4 changed files with 89 additions and 45 deletions
+5 -3
View File
@@ -3,7 +3,8 @@
if (!defined('BASEPATH')) exit('No direct script access allowed');
/**
*
* This is the super class for all those controllers that can only be called from command line
* It provides also an helper to display the possible calls
*/
abstract class CLI_Controller extends FHC_Controller
{
@@ -15,9 +16,9 @@ abstract class CLI_Controller extends FHC_Controller
/**
* Constructor
*/
public function __construct()
public function __construct()
{
parent::__construct();
parent::__construct();
// Checks if the controller is called from command line
$this->_isAllowed();
@@ -103,3 +104,4 @@ abstract class CLI_Controller extends FHC_Controller
}
}
}
+28 -19
View File
@@ -3,26 +3,34 @@
if (!defined('BASEPATH')) exit('No direct script access allowed');
/**
*
* This is the super class for a job.
* All the controllers that extends this class can only be called from command line.
* Provides utility methods to log into database
*/
abstract class JOB_Controller extends CLI_Controller
{
/**
* Constructor
*/
public function __construct()
public function __construct()
{
parent::__construct();
parent::__construct();
// Loads LogLib with different debug trace levels to get data of the job that extends this class
// It also specify parameters to set database fields
$this->load->library('LogLib', array(
'classIndex' => 5,
'functionIndex' => 5,
'lineIndex' => 4,
'dbLogType' => 'job', // required
'dbExecuteUser' => 'Cronjob system'
));
$this->load->library('LogLib',
array(
'classIndex' => 5,
'functionIndex' => 5,
'lineIndex' => 4,
'dbLogType' => 'job', // required
'dbExecuteUser' => 'Cronjob system',
'requestId' => 'JOB',
'requestDataFormatter' => function($data) {
return json_encode($data);
}
)
);
}
//------------------------------------------------------------------------------------------------------------------
@@ -33,7 +41,7 @@ abstract class JOB_Controller extends CLI_Controller
*/
protected function logInfo($response, $parameters = null)
{
$this->_log(LogLib::INFO, 'Cronjob info', $response, $parameters);
$this->_log(LogLib::INFO, $response, $parameters);
}
/**
@@ -41,7 +49,7 @@ abstract class JOB_Controller extends CLI_Controller
*/
protected function logDebug($response, $parameters = null)
{
$this->_log(LogLib::DEBUG, 'Cronjob debug', $response, $parameters);
$this->_log(LogLib::DEBUG, $response, $parameters);
}
/**
@@ -49,7 +57,7 @@ abstract class JOB_Controller extends CLI_Controller
*/
protected function logWarning($response, $parameters = null)
{
$this->_log(LogLib::WARNING, 'Cronjob warning', $response, $parameters);
$this->_log(LogLib::WARNING, $response, $parameters);
}
/**
@@ -57,7 +65,7 @@ abstract class JOB_Controller extends CLI_Controller
*/
protected function logError($response, $parameters = null)
{
$this->_log(LogLib::ERROR, 'Cronjob error', $response, $parameters);
$this->_log(LogLib::ERROR, $response, $parameters);
}
//------------------------------------------------------------------------------------------------------------------
@@ -66,7 +74,7 @@ abstract class JOB_Controller extends CLI_Controller
/**
* Writes a log to database
*/
private function _log($level, $requestId, $response, $parameters)
private function _log($level, $response, $parameters)
{
$data = new stdClass();
@@ -76,17 +84,18 @@ abstract class JOB_Controller extends CLI_Controller
switch($level)
{
case LogLib::INFO:
$this->loglib->logInfoDB($requestId, json_encode(success($data, LogLib::INFO)));
$this->loglib->logInfoDB($data);
break;
case LogLib::DEBUG:
$this->loglib->logDebugDB($requestId, json_encode(success($data, LogLib::DEBUG)));
$this->loglib->logDebugDB($data);
break;
case LogLib::WARNING:
$this->loglib->logWarningDB($requestId, json_encode(error($data, LogLib::WARNING)));
$this->loglib->logWarningDB($data);
break;
case LogLib::ERROR:
$this->loglib->logErrorDB($requestId, json_encode(error($data, LogLib::ERROR)));
$this->loglib->logErrorDB($data);
break;
}
}
}
+11 -11
View File
@@ -5,9 +5,10 @@ if (!defined("BASEPATH")) exit("No direct script access allowed");
/**
* Job Queue Worker
*
* This controller acts as interface of the JobsQueueLib that contains all the needed functionalities to operate with
* the Jobs Queue System
* This is an abstract class that provide basic functionalities, it has to be extended to broaden its logic
* This controller acts as interface of the JobsQueueLib that contains
* all the needed functionalities to operate with the Jobs Queue System
* This is an abstract class that provide basic functionalities,
* it has to be extended to broaden its logic
*/
abstract class JQW_Controller extends JOB_Controller
{
@@ -18,14 +19,13 @@ abstract class JQW_Controller extends JOB_Controller
{
parent::__construct();
// Loads LogLib with different parameters
$this->load->library('LogLib', array(
'classIndex' => 5,
'functionIndex' => 5,
'lineIndex' => 4,
'dbLogType' => 'job', // required
'dbExecuteUser' => 'Jobs queue system'
));
// Changes the needed configs for LogLib
$this->loglib->setConfigs(
array(
'dbExecuteUser' => 'Jobs queue system',
'requestId' => 'JQW'
)
);
// Loads JobsQueueLib library
$this->load->library('JobsQueueLib');