Merged in feature/HOR-4634 (pull request #6523)
HOR-4634 Approved-by: Julio Cesar Laura Avendaño <contact@julio-laura.com>
This commit is contained in:
@@ -2660,11 +2660,21 @@ class Bootstrap
|
|||||||
* @param array $context The log context
|
* @param array $context The log context
|
||||||
* @param string $workspace name workspace
|
* @param string $workspace name workspace
|
||||||
* @param string $file name file
|
* @param string $file name file
|
||||||
* @param string $pathData path of file
|
* @param boolean $readLoggingLevel
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
public static function registerMonolog($channel, $level, $message, $context, $workspace, $file = 'cron.log', $pathData = PATH_DATA)
|
public static function registerMonolog(
|
||||||
|
$channel,
|
||||||
|
$level,
|
||||||
|
$message,
|
||||||
|
$context,
|
||||||
|
$workspace,
|
||||||
|
$file = 'cron.log',
|
||||||
|
$readLoggingLevel = true
|
||||||
|
)
|
||||||
{
|
{
|
||||||
$registerLogger = MonologProvider::getSingleton($channel, $file);
|
$registerLogger = MonologProvider::getSingleton($channel, $file, $readLoggingLevel);
|
||||||
$registerLogger->addLog($level, $message, $context);
|
$registerLogger->addLog($level, $message, $context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ use Monolog\Formatter\LineFormatter;
|
|||||||
use Monolog\Handler\RotatingFileHandler;
|
use Monolog\Handler\RotatingFileHandler;
|
||||||
use Monolog\Logger;
|
use Monolog\Logger;
|
||||||
use Monolog\Processor\IntrospectionProcessor;
|
use Monolog\Processor\IntrospectionProcessor;
|
||||||
|
use ProcessMaker\Core\System;
|
||||||
|
|
||||||
class MonologProvider
|
class MonologProvider
|
||||||
{
|
{
|
||||||
@@ -66,29 +67,27 @@ class MonologProvider
|
|||||||
'EMERGENCY' => 600
|
'EMERGENCY' => 600
|
||||||
];
|
];
|
||||||
|
|
||||||
public function __construct($channel, $fileLog)
|
/**
|
||||||
|
* Construct of the class
|
||||||
|
*
|
||||||
|
* @param string $channel
|
||||||
|
* @param string $fileLog
|
||||||
|
* @param boolean $readLoggingLevel
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function __construct($channel, $fileLog, $readLoggingLevel = true)
|
||||||
{
|
{
|
||||||
// getting configuration from env.ini
|
//Set the minimum levelDebug that will be saved
|
||||||
$sysConf = System::getSystemConfiguration();
|
$levelDebug = $this->defineLevelDebug($readLoggingLevel);
|
||||||
|
|
||||||
//Set level debug
|
|
||||||
$levelDebug = 'DEBUG';
|
|
||||||
|
|
||||||
$this->setLevelDebug($levelDebug);
|
$this->setLevelDebug($levelDebug);
|
||||||
|
|
||||||
//Set path where the file will be saved
|
//Set path where the file will be saved
|
||||||
$defaultPath = $path = PATH_DATA . 'sites' . PATH_SEP . config('system.workspace') . PATH_SEP . 'log' . PATH_SEP;
|
$pathFile = $this->definePathFile();
|
||||||
if (isset($sysConf['logs_location'])) {
|
$this->setPathFile($pathFile);
|
||||||
$path = !empty($sysConf['logs_location']) ? $sysConf['logs_location'] : $path;
|
|
||||||
}
|
|
||||||
$this->setPathFile($path);
|
|
||||||
|
|
||||||
//Set maximal amount of files to keep (0 means unlimited)
|
//Set maximal amount of files to keep (0 means unlimited)
|
||||||
$maxFilesToKeep = 60;
|
$maxFilesToRotation = $this->defineMaxFiles();
|
||||||
if (isset($sysConf['logs_max_files'])) {
|
$this->setMaxFiles($maxFilesToRotation);
|
||||||
$maxFilesToKeep = !empty($sysConf['logs_max_files']) ? $sysConf['logs_max_files'] : $maxFilesToKeep;
|
|
||||||
}
|
|
||||||
$this->setMaxFiles($maxFilesToKeep);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The permissions are normally set at the operating system level, and it's the IT administrator responsibility to set the correct file permissions
|
* The permissions are normally set at the operating system level, and it's the IT administrator responsibility to set the correct file permissions
|
||||||
@@ -102,10 +101,76 @@ class MonologProvider
|
|||||||
$this->setConfig($channel, $fileLog);
|
$this->setConfig($channel, $fileLog);
|
||||||
|
|
||||||
$this->testWriteLog($channel, $fileLog, [
|
$this->testWriteLog($channel, $fileLog, [
|
||||||
$defaultPath
|
$pathFile
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function defines the debug level
|
||||||
|
* We will to check if the logging_level exist in the env.ini
|
||||||
|
*
|
||||||
|
* @param boolean $readLoggingLevel
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
private function defineLevelDebug($readLoggingLevel = true)
|
||||||
|
{
|
||||||
|
$levelDebug = 'INFO';
|
||||||
|
|
||||||
|
if ($readLoggingLevel) {
|
||||||
|
//In the parse_ini_file the word NONE are considered FALSE
|
||||||
|
if (defined('LOGGING_LEVEL')) {
|
||||||
|
$levelDebug = !empty(LOGGING_LEVEL) ? LOGGING_LEVEL : 'NONE';
|
||||||
|
} else {
|
||||||
|
//Getting configuration from env.ini
|
||||||
|
$sysConf = System::getSystemConfiguration();
|
||||||
|
$levelDebug = !empty($sysConf['logging_level']) ? $sysConf['logging_level'] : 'NONE';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $levelDebug;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function defines the path file
|
||||||
|
* We will to check if the logs_location exist in the env.ini
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
private function definePathFile()
|
||||||
|
{
|
||||||
|
$path = PATH_DATA . 'sites' . PATH_SEP . config('system.workspace') . PATH_SEP . 'log' . PATH_SEP;
|
||||||
|
|
||||||
|
if (defined('LOGS_LOCATION')) {
|
||||||
|
$path = !empty(LOGS_LOCATION) ? LOGS_LOCATION : $path;
|
||||||
|
} else {
|
||||||
|
$sysConf = System::getSystemConfiguration();
|
||||||
|
$path = !empty($sysConf['logs_location']) ? $sysConf['logs_location'] : $path;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $path;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function defines the max number of files
|
||||||
|
* We will to check if the logs_max_files exist in the env.ini
|
||||||
|
*
|
||||||
|
* @return integer
|
||||||
|
*/
|
||||||
|
private function defineMaxFiles()
|
||||||
|
{
|
||||||
|
$maxFilesToRotation = 60;
|
||||||
|
|
||||||
|
if (defined('LOGS_MAX_FILES')) {
|
||||||
|
$maxFilesToRotation = !empty(LOGS_MAX_FILES) ? LOGS_MAX_FILES : $maxFilesToRotation;
|
||||||
|
} else {
|
||||||
|
$sysConf = System::getSystemConfiguration();
|
||||||
|
$maxFilesToRotation = !empty($sysConf['logs_max_files']) ? $sysConf['logs_max_files'] : $maxFilesToRotation;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $maxFilesToRotation;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test write log
|
* Test write log
|
||||||
*
|
*
|
||||||
@@ -128,7 +193,10 @@ class MonologProvider
|
|||||||
|
|
||||||
if (!file_exists($this->getPathFile() . $timedFilename)) {
|
if (!file_exists($this->getPathFile() . $timedFilename)) {
|
||||||
try {
|
try {
|
||||||
$this->getLogger()->addInfo('Start writing the log file');
|
$level = $this->getLevelDebug();
|
||||||
|
if (!empty($level)) {
|
||||||
|
$this->getLogger()->addRecord($level, 'Start writing the log file');
|
||||||
|
}
|
||||||
} catch (UnexpectedValueException $exception) {
|
} catch (UnexpectedValueException $exception) {
|
||||||
//In case that the file can not be written, it will be written to the standard log file.
|
//In case that the file can not be written, it will be written to the standard log file.
|
||||||
error_log($exception->getMessage());
|
error_log($exception->getMessage());
|
||||||
@@ -356,23 +424,28 @@ class MonologProvider
|
|||||||
*/
|
*/
|
||||||
public function setLevelDebug($levelDebug)
|
public function setLevelDebug($levelDebug)
|
||||||
{
|
{
|
||||||
$level = static::$levels['DEBUG'];
|
//If is a valid, we will to define the level
|
||||||
if (isset(static::$levels[$levelDebug])) {
|
if (isset(static::$levels[$levelDebug])) {
|
||||||
$level = static::$levels[$levelDebug];
|
$level = static::$levels[$levelDebug];
|
||||||
}
|
|
||||||
$this->levelDebug = $level;
|
$this->levelDebug = $level;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* to get singleton instance
|
* To get singleton instance
|
||||||
*
|
*
|
||||||
* @access public
|
* @access public
|
||||||
|
*
|
||||||
|
* @param string $channel
|
||||||
|
* @param string $fileLog
|
||||||
|
* @param boolean $readLoggingLevel
|
||||||
|
*
|
||||||
* @return object
|
* @return object
|
||||||
*/
|
*/
|
||||||
public static function getSingleton($channel, $fileLog)
|
public static function getSingleton($channel, $fileLog, $readLoggingLevel = true)
|
||||||
{
|
{
|
||||||
if (self::$instance === null) {
|
if (self::$instance === null) {
|
||||||
self::$instance = new MonologProvider($channel, $fileLog);
|
self::$instance = new MonologProvider($channel, $fileLog, $readLoggingLevel);
|
||||||
} else {
|
} else {
|
||||||
self::$instance->setConfig($channel, $fileLog);
|
self::$instance->setConfig($channel, $fileLog);
|
||||||
}
|
}
|
||||||
@@ -401,9 +474,13 @@ class MonologProvider
|
|||||||
* @param int $level The logging level
|
* @param int $level The logging level
|
||||||
* @param string $message The log message
|
* @param string $message The log message
|
||||||
* @param array $context The log context
|
* @param array $context The log context
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function addLog($level, $message, $context)
|
public function addLog($level, $message, $context)
|
||||||
{
|
{
|
||||||
|
if (!empty($this->getLevelDebug())) {
|
||||||
$this->getLogger()->addRecord($level, $message, $context);
|
$this->getLogger()->addRecord($level, $message, $context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@@ -11,6 +11,7 @@ use Symfony\Component\Finder\Finder;
|
|||||||
|
|
||||||
class AuditLog
|
class AuditLog
|
||||||
{
|
{
|
||||||
|
const READ_LOGGING_LEVEL = false;
|
||||||
private $actions = [];
|
private $actions = [];
|
||||||
private $columns;
|
private $columns;
|
||||||
private $pageSizeDefault = 20;
|
private $pageSizeDefault = 20;
|
||||||
@@ -293,7 +294,15 @@ class AuditLog
|
|||||||
$context['usrName'] = $this->userFullname;
|
$context['usrName'] = $this->userFullname;
|
||||||
$context['action'] = $action;
|
$context['action'] = $action;
|
||||||
$context['description'] = $value;
|
$context['description'] = $value;
|
||||||
Bootstrap::registerMonolog($action, 200, $action, $context, $context['workspace'], 'audit.log');
|
Bootstrap::registerMonolog(
|
||||||
|
$action,
|
||||||
|
200,
|
||||||
|
$action,
|
||||||
|
$context,
|
||||||
|
$context['workspace'],
|
||||||
|
'audit.log',
|
||||||
|
self::READ_LOGGING_LEVEL
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -61,7 +61,9 @@ class System
|
|||||||
'redirect_to_mobile' => 0,
|
'redirect_to_mobile' => 0,
|
||||||
'disable_php_upload_execution' => 0,
|
'disable_php_upload_execution' => 0,
|
||||||
'disable_download_documents_session_validation' => 0,
|
'disable_download_documents_session_validation' => 0,
|
||||||
'logs_max_files' => 60
|
'logs_max_files' => 60,
|
||||||
|
'logs_location' => '',
|
||||||
|
'logging_level' => 'INFO'
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -322,6 +322,9 @@ define('LEAVE_CASE_WARNING', $config['leave_case_warning']);
|
|||||||
define('REDIRECT_TO_MOBILE', $config['redirect_to_mobile']);
|
define('REDIRECT_TO_MOBILE', $config['redirect_to_mobile']);
|
||||||
define('DISABLE_PHP_UPLOAD_EXECUTION', $config['disable_php_upload_execution']);
|
define('DISABLE_PHP_UPLOAD_EXECUTION', $config['disable_php_upload_execution']);
|
||||||
define('DISABLE_DOWNLOAD_DOCUMENTS_SESSION_VALIDATION', $config['disable_download_documents_session_validation']);
|
define('DISABLE_DOWNLOAD_DOCUMENTS_SESSION_VALIDATION', $config['disable_download_documents_session_validation']);
|
||||||
|
define('LOGS_MAX_FILES', $config['logs_max_files']);
|
||||||
|
define('LOGS_LOCATION', $config['logs_location']);
|
||||||
|
define('LOGGING_LEVEL', $config['logging_level']);
|
||||||
|
|
||||||
// IIS Compatibility, SERVER_ADDR doesn't exist on that env, so we need to define it.
|
// IIS Compatibility, SERVER_ADDR doesn't exist on that env, so we need to define it.
|
||||||
$_SERVER['SERVER_ADDR'] = isset($_SERVER['SERVER_ADDR']) ? $_SERVER['SERVER_ADDR'] : $_SERVER['SERVER_NAME'];
|
$_SERVER['SERVER_ADDR'] = isset($_SERVER['SERVER_ADDR']) ? $_SERVER['SERVER_ADDR'] : $_SERVER['SERVER_NAME'];
|
||||||
|
|||||||
Reference in New Issue
Block a user