Log : always log the same structure, and add a delimiter at the end

This will allow to parse the logs more easily !
This commit is contained in:
Pierre Goiffon
2021-10-20 15:16:57 +02:00
parent ec8c2ca122
commit ef6d7925fc

View File

@@ -502,20 +502,22 @@ class FileLog
protected function Write($sText, $sLevel = '', $sChannel = '', $aContext = array()) 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)." | "; $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; return;
} }
$hLogFile = @fopen($sLogFilePath, 'a'); $hLogFile = @fopen($sLogFilePath, 'a');
if ($hLogFile !== false) if ($hLogFile !== false) {
{
flock($hLogFile, LOCK_EX); flock($hLogFile, LOCK_EX);
$sDate = date('Y-m-d H:i:s'); $sDate = date('Y-m-d H:i:s');
if (empty($aContext)) { if (empty($aContext)) {