Drop the bSearchSecretWords param from logger

This commit is contained in:
the-djmaze 2024-02-05 22:30:23 +01:00
parent e1d95f8632
commit 83659ff62d
4 changed files with 21 additions and 22 deletions

View file

@ -29,10 +29,9 @@ trait Inherit
$this->oLogger = $oLogger; $this->oLogger = $oLogger;
} }
public function logWrite(string $sDesc, int $iType = \LOG_INFO, public function logWrite(string $sDesc, int $iType = \LOG_INFO, string $sName = '', bool $bDiplayCrLf = false): bool
string $sName = '', bool $bSearchSecretWords = true, bool $bDiplayCrLf = false): bool
{ {
return $this->oLogger && $this->oLogger->Write($sDesc, $iType, $sName, $bSearchSecretWords, $bDiplayCrLf); return $this->oLogger && $this->oLogger->Write($sDesc, $iType, $sName, $bDiplayCrLf);
} }
public function logException(\Throwable $oException, int $iType = \LOG_NOTICE, string $sName = ''): void public function logException(\Throwable $oException, int $iType = \LOG_NOTICE, string $sName = ''): void

View file

@ -112,11 +112,12 @@ class Logger extends \SplFixedArray
string $sWord string $sWord
) : void ) : void
{ {
// $this->bShowSecrets && $this->Write("AddSecret '{$sWord}'", \LOG_INFO, '', false); // $this->bShowSecrets && $this->Write("AddSecret '{$sWord}'", \LOG_INFO);
$sWord = \trim($sWord); $sWord = \trim($sWord);
if (\strlen($sWord)) { if (\strlen($sWord)) {
$this->aSecretWords[] = $sWord; $this->aSecretWords[] = $sWord;
$this->aSecretWords = \array_unique($this->aSecretWords); $this->aSecretWords = \array_unique($this->aSecretWords);
\usort($this->aSecretWords, fn($a,$b) => \strlen($b) - \strlen($a));
} }
} }
@ -220,8 +221,7 @@ class Logger extends \SplFixedArray
} }
} }
public function Write(string $sDesc, int $iType = \LOG_INFO, public function Write(string $sDesc, int $iType = \LOG_INFO, string $sName = '', bool $bDiplayCrLf = false) : bool
string $sName = '', bool $bSearchSecretWords = true, bool $bDiplayCrLf = false) : bool
{ {
if ($this->iLevel < $iType) { if ($this->iLevel < $iType) {
return true; return true;
@ -229,7 +229,7 @@ class Logger extends \SplFixedArray
$this->bUsed = true; $this->bUsed = true;
if ($bSearchSecretWords && !$this->bShowSecrets && $this->aSecretWords) { if (!$this->bShowSecrets && $this->aSecretWords) {
$sDesc = \str_replace($this->aSecretWords, '*******', $sDesc); $sDesc = \str_replace($this->aSecretWords, '*******', $sDesc);
} }

View file

@ -187,9 +187,9 @@ abstract class Base
{ {
if ($this->oLogger) { if ($this->oLogger) {
if ($mData instanceof \Throwable) { if ($mData instanceof \Throwable) {
$this->oLogger->WriteException($mData, \LOG_ERR, 'SQL'); $this->logException($mData, \LOG_ERR, 'SQL');
} else if (\is_scalar($mData)) { } else if (\is_scalar($mData)) {
$this->oLogger->Write((string) $mData, \LOG_INFO, 'SQL'); $this->logWrite((string) $mData, \LOG_INFO, 'SQL');
} else { } else {
$this->oLogger->WriteDump($mData, \LOG_INFO, 'SQL'); $this->oLogger->WriteDump($mData, \LOG_INFO, 'SQL');
} }

View file

@ -110,7 +110,7 @@ class ServiceActions
$sMethodName = 'Do'.$sAction; $sMethodName = 'Do'.$sAction;
$this->Logger()->Write('Action: '.$sMethodName, \LOG_INFO, 'JSON'); $this->oActions->logWrite('Action: '.$sMethodName, \LOG_INFO, 'JSON');
$aPost = $_POST ?? null; $aPost = $_POST ?? null;
if ($aPost) { if ($aPost) {
@ -130,7 +130,7 @@ class ServiceActions
break; break;
} }
*/ */
$this->Logger()->Write(Utils::jsonEncode($aPost), \LOG_INFO, 'POST'); $this->oActions->logWrite(Utils::jsonEncode($aPost), \LOG_INFO, 'POST');
} else if (3 < \count($this->aPaths) && $this->oHttp->IsGet()) { } else if (3 < \count($this->aPaths) && $this->oHttp->IsGet()) {
$this->oActions->SetActionParams(array( $this->oActions->SetActionParams(array(
'RawKey' => empty($this->aPaths[3]) ? '' : $this->aPaths[3] 'RawKey' => empty($this->aPaths[3]) ? '' : $this->aPaths[3]
@ -184,15 +184,15 @@ class ServiceActions
if ($this->Logger()->IsEnabled()) { if ($this->Logger()->IsEnabled()) {
if (\strlen($sObResult)) { if (\strlen($sObResult)) {
$this->Logger()->Write($sObResult, \LOG_ERR, 'OB-DATA'); $this->oActions->logWrite($sObResult, \LOG_ERR, 'OB-DATA');
} }
if ($oException) { if ($oException) {
$this->Logger()->WriteException($oException, \LOG_ERR); $this->oActions->logException($oException, \LOG_ERR);
} }
$iLimit = (int) $this->Config()->Get('labs', 'log_ajax_response_write_limit', 0); $iLimit = (int) $this->Config()->Get('labs', 'log_ajax_response_write_limit', 0);
$this->Logger()->Write(0 < $iLimit && $iLimit < \strlen($sResult) $this->oActions->logWrite(0 < $iLimit && $iLimit < \strlen($sResult)
? \substr($sResult, 0, $iLimit).'...' : $sResult, \LOG_INFO, 'JSON'); ? \substr($sResult, 0, $iLimit).'...' : $sResult, \LOG_INFO, 'JSON');
} }
@ -252,10 +252,10 @@ class ServiceActions
$sObResult = \ob_get_clean(); $sObResult = \ob_get_clean();
if (\strlen($sObResult)) { if (\strlen($sObResult)) {
$this->Logger()->Write($sObResult, \LOG_ERR, 'OB-DATA'); $this->oActions->logWrite($sObResult, \LOG_ERR, 'OB-DATA');
} }
$this->Logger()->Write($sResult, \LOG_INFO, 'UPLOAD'); $this->oActions->logWrite($sResult, \LOG_INFO, 'UPLOAD');
return $sResult; return $sResult;
} }
@ -369,12 +369,12 @@ class ServiceActions
} }
if (\strlen($sRawError)) { if (\strlen($sRawError)) {
$this->Logger()->Write($sRawError, \LOG_ERR); $this->oActions->logWrite($sRawError, \LOG_ERR);
$this->Logger()->WriteDump($this->aPaths, \LOG_ERR, 'PATHS'); $this->Logger()->WriteDump($this->aPaths, \LOG_ERR, 'PATHS');
} }
if ($oException) { if ($oException) {
$this->Logger()->WriteException($oException, \LOG_ERR, 'RAW'); $this->oActions->logException($oException, \LOG_ERR, 'RAW');
} }
return $sResult; return $sResult;
@ -481,7 +481,7 @@ class ServiceActions
} }
catch (\Throwable $oException) catch (\Throwable $oException)
{ {
$this->Logger()->WriteException($oException, \LOG_ERR, 'LESS'); $this->oActions->logException($oException, \LOG_ERR, 'LESS');
} }
} }
@ -526,7 +526,7 @@ class ServiceActions
$this->oHttp->ServerNoCache(); $this->oHttp->ServerNoCache();
\header('Content-Type: text/plain; charset=utf-8'); \header('Content-Type: text/plain; charset=utf-8');
$this->oActions->Logger()->Write('Pong', \LOG_INFO, 'PING'); $this->oActions->logWrite('Pong', \LOG_INFO, 'PING');
return 'Pong'; return 'Pong';
} }
@ -598,7 +598,7 @@ class ServiceActions
} }
catch (\Throwable $oException) catch (\Throwable $oException)
{ {
$this->Logger()->WriteException($oException); $this->oActions->logException($oException);
} }
} }
} }
@ -632,7 +632,7 @@ class ServiceActions
$this->oHttp->ServerNoCache(); $this->oHttp->ServerNoCache();
try { try {
$sResult = Utils::jsonEncode($this->oActions->AppData($bAdmin)); $sResult = Utils::jsonEncode($this->oActions->AppData($bAdmin));
$this->Logger()->Write($sResult, \LOG_INFO, 'APPDATA'); $this->oActions->logWrite($sResult, \LOG_INFO, 'APPDATA');
return $sResult; return $sResult;
} catch (\Throwable $oException) { } catch (\Throwable $oException) {
$this->Logger()->WriteExceptionShort($oException); $this->Logger()->WriteExceptionShort($oException);