log : factorize level & context

This commit is contained in:
Pierre Goiffon
2019-12-10 09:39:46 +01:00
parent e5c49e3bd4
commit 332c6eb33c

View File

@@ -201,41 +201,34 @@ class FileLog
public function Error($sText, $sChannel = '', $aContext = array())
{
$sLevel = str_pad(__FUNCTION__, 7).' | ';
$sChannel = empty($sChannel) ? '' : " | $sChannel";
$this->Write("{$sLevel}{$sText}{$sChannel}", $aContext);
$this->Write($sText, __FUNCTION__, $sChannel, $aContext);
}
public function Warning($sText, $sChannel = '', $aContext = array())
{
$sLevel = str_pad(__FUNCTION__, 7).' | ';
$sChannel = empty($sChannel) ? '' : " | $sChannel";
$this->Write("{$sLevel}{$sText}{$sChannel}", $aContext);
$this->Write($sText, __FUNCTION__, $sChannel, $aContext);
}
public function Info($sText, $sChannel = '', $aContext = array())
{
$sLevel = str_pad(__FUNCTION__, 7).' | ';
$sChannel = empty($sChannel) ? '' : " | $sChannel";
$this->Write("{$sLevel}{$sText}{$sChannel}", $aContext);
$this->Write($sText, __FUNCTION__, $sChannel, $aContext);
}
public function Ok($sText, $sChannel = '', $aContext = array())
{
$sLevel = str_pad(__FUNCTION__, 7).' | ';
$sChannel = empty($sChannel) ? '' : " | $sChannel";
$this->Write("{$sLevel}{$sText}{$sChannel}", $aContext);
$this->Write($sText, __FUNCTION__, $sChannel, $aContext);
}
public function Debug($sText, $sChannel = '', $aContext = array())
{
$sLevel = str_pad(__FUNCTION__, 7).' | ';
$sChannel = empty($sChannel) ? '' : " | $sChannel";
$this->Write("{$sLevel}{$sText}{$sChannel}", $aContext);
$this->Write($sText, __FUNCTION__, $sChannel, $aContext);
}
protected function Write($sText, $aContext = array())
protected function Write($sText, $sLevel = '', $sChannel = '', $aContext = array())
{
$sTextPrefix = empty($sLevel) ? '' : (str_pad($sLevel, 7).' | ');
$sTextSuffix = empty($sChannel) ? '' : " | $sChannel";
$sText = "{$sTextPrefix}{$sText}{$sTextSuffix}";
$sLogFilePath = $this->oFileNameBuilder->GetLogFilePath();
if (empty($sLogFilePath))