From c09bd2bfc6b356d57ec6fca6c5ee23238efc8fff Mon Sep 17 00:00:00 2001 From: bruno DA SILVA Date: Thu, 19 Dec 2019 11:17:18 +0100 Subject: [PATCH] 2626 - log modularity: filterable logs using minimal log level per channel :loud_sound: Adding log level Trace, which is not logged by default (as for Debug) --- core/log.class.inc.php | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/core/log.class.inc.php b/core/log.class.inc.php index da20795ec..e9a505de5 100644 --- a/core/log.class.inc.php +++ b/core/log.class.inc.php @@ -224,6 +224,12 @@ class FileLog $this->Write($sText, __FUNCTION__, $sChannel, $aContext); } + public function Trace($sText, $sChannel = '', $aContext = array()) + { + $this->Write($sText, __FUNCTION__, $sChannel, $aContext); + } + + protected function Write($sText, $sLevel = '', $sChannel = '', $aContext = array()) { $sTextPrefix = empty($sLevel) ? '' : (str_pad($sLevel, 7).' | '); @@ -261,25 +267,24 @@ abstract class LogAPI { const CHANNEL_DEFAULT = ''; - const LEVEL_DEBUG = 'Debug'; - const LEVEL_OK = 'Ok'; - const LEVEL_INFO = 'Info'; - const LEVEL_WARNING = 'Warning'; const LEVEL_ERROR = 'Error'; -// const LEVEL_CRITICAL = 'Critical'; -// const LEVEL_ALERT = 'Alert'; -// const LEVEL_EMERGENCY = 'Emergency'; - - protected static $m_oMockMetaModelConfig = null; + const LEVEL_WARNING = 'Warning'; + const LEVEL_INFO = 'Info'; + const LEVEL_OK = 'Ok'; + const LEVEL_DEBUG = 'Debug'; + const LEVEL_TRACE = 'Trace'; protected static $aLevelsPriority = array( - self::LEVEL_DEBUG => 100, - self::LEVEL_OK => 150, - self::LEVEL_INFO => 200, - self::LEVEL_WARNING => 300, self::LEVEL_ERROR => 400, + self::LEVEL_WARNING => 300, + self::LEVEL_INFO => 200, + self::LEVEL_OK => 200, + self::LEVEL_DEBUG => 100, + self::LEVEL_TRACE => 50, ); + protected static $m_oMockMetaModelConfig = null; + public static function Enable($sTargetFile) { // m_oFileLog is not defined as a class attribute so that each impl will have its own @@ -317,6 +322,11 @@ abstract class LogAPI static::Log(self::LEVEL_DEBUG, $sMessage, $sChannel, $aContext); } + public static function Trace($sMessage, $sChannel = null, $aContext = array()) + { + static::Log(self::LEVEL_TRACE, $sMessage, $sChannel, $aContext); + } + public static function Log($sLevel, $sMessage, $sChannel = null, $aContext = array()) { if (! static::$m_oFileLog)