From 891912327907ec39c59742a8a81c55a863c902ee Mon Sep 17 00:00:00 2001 From: Paula Quispe Date: Wed, 13 Jun 2018 15:28:25 -0400 Subject: [PATCH] HOR-4634 --- gulliver/system/class.bootstrap.php | 16 ++- gulliver/system/class.monologProvider.php | 127 ++++++++++++++---- .../src/ProcessMaker/AuditLog/AuditLog.php | 11 +- .../engine/src/ProcessMaker/Core/System.php | 4 +- workflow/public_html/sysGeneric.php | 3 + 5 files changed, 131 insertions(+), 30 deletions(-) diff --git a/gulliver/system/class.bootstrap.php b/gulliver/system/class.bootstrap.php index cff95964a..dd86c29a2 100644 --- a/gulliver/system/class.bootstrap.php +++ b/gulliver/system/class.bootstrap.php @@ -2660,11 +2660,21 @@ class Bootstrap * @param array $context The log context * @param string $workspace name workspace * @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); } diff --git a/gulliver/system/class.monologProvider.php b/gulliver/system/class.monologProvider.php index b4ffeadd3..b90673e12 100644 --- a/gulliver/system/class.monologProvider.php +++ b/gulliver/system/class.monologProvider.php @@ -4,6 +4,7 @@ use Monolog\Formatter\LineFormatter; use Monolog\Handler\RotatingFileHandler; use Monolog\Logger; use Monolog\Processor\IntrospectionProcessor; +use ProcessMaker\Core\System; class MonologProvider { @@ -66,29 +67,27 @@ class MonologProvider '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 - $sysConf = System::getSystemConfiguration(); - - //Set level debug - $levelDebug = 'DEBUG'; - + //Set the minimum levelDebug that will be saved + $levelDebug = $this->defineLevelDebug($readLoggingLevel); $this->setLevelDebug($levelDebug); //Set path where the file will be saved - $defaultPath = $path = PATH_DATA . 'sites' . PATH_SEP . config('system.workspace') . PATH_SEP . 'log' . PATH_SEP; - if (isset($sysConf['logs_location'])) { - $path = !empty($sysConf['logs_location']) ? $sysConf['logs_location'] : $path; - } - $this->setPathFile($path); + $pathFile = $this->definePathFile(); + $this->setPathFile($pathFile); //Set maximal amount of files to keep (0 means unlimited) - $maxFilesToKeep = 60; - if (isset($sysConf['logs_max_files'])) { - $maxFilesToKeep = !empty($sysConf['logs_max_files']) ? $sysConf['logs_max_files'] : $maxFilesToKeep; - } - $this->setMaxFiles($maxFilesToKeep); + $maxFilesToRotation = $this->defineMaxFiles(); + $this->setMaxFiles($maxFilesToRotation); /** * 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->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 * @@ -128,7 +193,10 @@ class MonologProvider if (!file_exists($this->getPathFile() . $timedFilename)) { 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) { //In case that the file can not be written, it will be written to the standard log file. error_log($exception->getMessage()); @@ -356,23 +424,28 @@ class MonologProvider */ public function setLevelDebug($levelDebug) { - $level = static::$levels['DEBUG']; + //If is a valid, we will to define the level if (isset(static::$levels[$levelDebug])) { $level = static::$levels[$levelDebug]; + $this->levelDebug = $level; } - $this->levelDebug = $level; } /** - * to get singleton instance + * To get singleton instance * * @access public + * + * @param string $channel + * @param string $fileLog + * @param boolean $readLoggingLevel + * * @return object */ - public static function getSingleton($channel, $fileLog) + public static function getSingleton($channel, $fileLog, $readLoggingLevel = true) { if (self::$instance === null) { - self::$instance = new MonologProvider($channel, $fileLog); + self::$instance = new MonologProvider($channel, $fileLog, $readLoggingLevel); } else { self::$instance->setConfig($channel, $fileLog); } @@ -401,9 +474,13 @@ class MonologProvider * @param int $level The logging level * @param string $message The log message * @param array $context The log context + * + * @return void */ public function addLog($level, $message, $context) { - $this->getLogger()->addRecord($level, $message, $context); + if (!empty($this->getLevelDebug())) { + $this->getLogger()->addRecord($level, $message, $context); + } } } \ No newline at end of file diff --git a/workflow/engine/src/ProcessMaker/AuditLog/AuditLog.php b/workflow/engine/src/ProcessMaker/AuditLog/AuditLog.php index 83946cfb6..96c2232ac 100644 --- a/workflow/engine/src/ProcessMaker/AuditLog/AuditLog.php +++ b/workflow/engine/src/ProcessMaker/AuditLog/AuditLog.php @@ -11,6 +11,7 @@ use Symfony\Component\Finder\Finder; class AuditLog { + const READ_LOGGING_LEVEL = false; private $actions = []; private $columns; private $pageSizeDefault = 20; @@ -293,7 +294,15 @@ class AuditLog $context['usrName'] = $this->userFullname; $context['action'] = $action; $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 + ); } /** diff --git a/workflow/engine/src/ProcessMaker/Core/System.php b/workflow/engine/src/ProcessMaker/Core/System.php index 516f199fa..df1a037dc 100644 --- a/workflow/engine/src/ProcessMaker/Core/System.php +++ b/workflow/engine/src/ProcessMaker/Core/System.php @@ -61,7 +61,9 @@ class System 'redirect_to_mobile' => 0, 'disable_php_upload_execution' => 0, 'disable_download_documents_session_validation' => 0, - 'logs_max_files' => 60 + 'logs_max_files' => 60, + 'logs_location' => '', + 'logging_level' => 'INFO' ); /** diff --git a/workflow/public_html/sysGeneric.php b/workflow/public_html/sysGeneric.php index fda834582..42c96af9e 100644 --- a/workflow/public_html/sysGeneric.php +++ b/workflow/public_html/sysGeneric.php @@ -341,6 +341,9 @@ define('LEAVE_CASE_WARNING', $config['leave_case_warning']); define('REDIRECT_TO_MOBILE', $config['redirect_to_mobile']); define('DISABLE_PHP_UPLOAD_EXECUTION', $config['disable_php_upload_execution']); 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. $_SERVER['SERVER_ADDR'] = isset($_SERVER['SERVER_ADDR']) ? $_SERVER['SERVER_ADDR'] : $_SERVER['SERVER_NAME'];