From ef6d7925fc6383efbdbb1e3bade567f6c0747452 Mon Sep 17 00:00:00 2001 From: Pierre Goiffon Date: Wed, 20 Oct 2021 15:16:57 +0200 Subject: [PATCH] Log : always log the same structure, and add a delimiter at the end This will allow to parse the logs more easily ! --- core/log.class.inc.php | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/core/log.class.inc.php b/core/log.class.inc.php index 072db948a..db439e429 100644 --- a/core/log.class.inc.php +++ b/core/log.class.inc.php @@ -502,20 +502,22 @@ class FileLog protected function Write($sText, $sLevel = '', $sChannel = '', $aContext = array()) { - $sTextPrefix = empty($sLevel) ? '' : (str_pad($sLevel, 7).' | '); + $sTextPrefix = empty($sLevel) ? '' : (str_pad($sLevel, 7)); + $sTextPrefix .= ' | '; $sTextPrefix .= str_pad(UserRights::GetUserId(), 5)." | "; - $sTextSuffix = empty($sChannel) ? '' : " | $sChannel"; - $sText = "{$sTextPrefix}{$sText}{$sTextSuffix}"; - $sLogFilePath = $this->oFileNameBuilder->GetLogFilePath(); - if (empty($sLogFilePath)) - { + $sTextSuffix = ' | '.(empty($sChannel) ? '' : $sChannel); + $sTextSuffix .= ' |||'; + + $sText = "{$sTextPrefix}{$sText}{$sTextSuffix}"; + + $sLogFilePath = $this->oFileNameBuilder->GetLogFilePath(); + if (empty($sLogFilePath)) { return; } $hLogFile = @fopen($sLogFilePath, 'a'); - if ($hLogFile !== false) - { + if ($hLogFile !== false) { flock($hLogFile, LOCK_EX); $sDate = date('Y-m-d H:i:s'); if (empty($aContext)) {