From 3e3f85aaeb9bfb101785754bb0c7c44ae7bdfed9 Mon Sep 17 00:00:00 2001 From: the-djmaze <> Date: Mon, 24 Oct 2022 12:28:14 +0200 Subject: [PATCH] Improved logger more --- .../0.0.0/app/libraries/MailSo/Log/Logger.php | 42 +++++++++---------- .../app/libraries/MailSo/Net/NetClient.php | 2 +- .../v/0.0.0/app/libraries/RainLoop/Api.php | 5 +-- 3 files changed, 22 insertions(+), 27 deletions(-) diff --git a/snappymail/v/0.0.0/app/libraries/MailSo/Log/Logger.php b/snappymail/v/0.0.0/app/libraries/MailSo/Log/Logger.php index a880ff84a..8480f2d1d 100644 --- a/snappymail/v/0.0.0/app/libraries/MailSo/Log/Logger.php +++ b/snappymail/v/0.0.0/app/libraries/MailSo/Log/Logger.php @@ -25,17 +25,16 @@ class Logger extends \SplFixedArray private $bShowSecrets = false; - function __construct(bool $bRegPhpErrorHandler = true) + function __construct(bool $bMainLogger = false) { parent::__construct(); - if ($bRegPhpErrorHandler) + if ($bMainLogger) { \set_error_handler(array($this, '__phpErrorHandler')); \set_exception_handler(array($this, '__phpExceptionHandler')); + \register_shutdown_function(array($this, '__loggerShutDown')); } - - \register_shutdown_function(array($this, '__loggerShutDown')); } /** @@ -67,8 +66,8 @@ class Logger extends \SplFixedArray public function AddSecret(string $sWord) : void { - if (\strlen(\trim($sWord))) - { + $sWord = \strlen(\trim($sWord)); + if ($sWord) { $this->aSecretWords[] = $sWord; $this->aSecretWords = \array_unique($this->aSecretWords); } @@ -80,7 +79,7 @@ class Logger extends \SplFixedArray return $this; } - public function IsShowSecter() : bool + public function ShowSecrets() : bool { return $this->bShowSecrets; } @@ -182,29 +181,26 @@ class Logger extends \SplFixedArray } /** - * @param mixed $oValue + * @param mixed $mValue */ - public function WriteDump($oValue, int $iType = \LOG_INFO, string $sName = '', - bool $bSearchSecretWords = false, bool $bDiplayCrLf = false) : bool + public function WriteDump($mValue, int $iType = \LOG_INFO, string $sName = '') : bool { - return $this->Write(\print_r($oValue, true), $iType, $sName, $bSearchSecretWords, $bDiplayCrLf); + return $this->Write(\print_r($mValue, true), $iType, $sName); } - public function WriteException(\Throwable $oException, int $iType = \LOG_NOTICE, string $sName = '', - bool $bSearchSecretWords = true, bool $bDiplayCrLf = false) : bool - { - if (isset($oException->__LOGINNED__)) { - return true; - } - $oException->__LOGINNED__ = true; - return $this->Write((string) $oException, $iType, $sName, $bSearchSecretWords, $bDiplayCrLf); - } - - public function WriteExceptionShort(\Throwable $oException, int $iType = \LOG_NOTICE) : void + public function WriteException(\Throwable $oException, int $iType = \LOG_NOTICE, string $sName = '') : void { if (!isset($oException->__LOGINNED__)) { $oException->__LOGINNED__ = true; - $this->Write($oException->getMessage(), $iType); + $this->Write((string) $oException, $iType, $sName); + } + } + + public function WriteExceptionShort(\Throwable $oException, int $iType = \LOG_NOTICE, string $sName = '') : void + { + if (!isset($oException->__LOGINNED__)) { + $oException->__LOGINNED__ = true; + $this->Write($oException->getMessage(), $iType, $sName); } } } diff --git a/snappymail/v/0.0.0/app/libraries/MailSo/Net/NetClient.php b/snappymail/v/0.0.0/app/libraries/MailSo/Net/NetClient.php index 0e85c20d8..a61800e3a 100644 --- a/snappymail/v/0.0.0/app/libraries/MailSo/Net/NetClient.php +++ b/snappymail/v/0.0.0/app/libraries/MailSo/Net/NetClient.php @@ -304,7 +304,7 @@ abstract class NetClient $bFake = \strlen($sFakeRaw); $sRaw .= "\r\n"; - if ($this->oLogger && $this->oLogger->IsShowSecter()) + if ($this->oLogger && $this->oLogger->ShowSecrets()) { $bFake = false; } diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Api.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Api.php index b57993039..b609fb31f 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Api.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Api.php @@ -51,12 +51,11 @@ abstract class Api static $oLogger = null; if (!$oLogger) { $oConfig = static::Config(); - $oLogger = new \MailSo\Log\Logger; + $oLogger = new \MailSo\Log\Logger(true); + $oLogger->SetShowSecrets(!$oConfig->Get('logs', 'hide_passwords', true)); if ($oConfig->Get('debug', 'enable', false)) { - $oLogger->SetShowSecrets(!$oConfig->Get('logs', 'hide_passwords', true)); $oLogger->SetLevel(\LOG_DEBUG); } else if ($oConfig->Get('logs', 'enable', false)) { - $oLogger->SetShowSecrets(!$oConfig->Get('logs', 'hide_passwords', true)); $oLogger->SetLevel(\max(3, \RainLoop\Api::Config()->Get('logs', 'level', \LOG_WARNING))); } }