mirror of
https://github.com/the-djmaze/snappymail.git
synced 2024-09-20 23:55:55 +08:00
Improved logging.
Added "[logs]write_on_timeout_only" settings
This commit is contained in:
parent
1250efa445
commit
23c299ac9e
|
@ -33,6 +33,11 @@ abstract class Driver
|
||||||
*/
|
*/
|
||||||
protected $bTypedPrefix;
|
protected $bTypedPrefix;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
private $iWriteOnTimeoutOnly;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var bool
|
* @var bool
|
||||||
*/
|
*/
|
||||||
|
@ -58,6 +63,7 @@ abstract class Driver
|
||||||
$this->bTimePrefix = true;
|
$this->bTimePrefix = true;
|
||||||
$this->bTypedPrefix = true;
|
$this->bTypedPrefix = true;
|
||||||
|
|
||||||
|
$this->iWriteOnTimeoutOnly = 0;
|
||||||
$this->bWriteOnErrorOnly = false;
|
$this->bWriteOnErrorOnly = false;
|
||||||
$this->bFlushCache = false;
|
$this->bFlushCache = false;
|
||||||
$this->aCache = array();
|
$this->aCache = array();
|
||||||
|
@ -94,6 +100,22 @@ abstract class Driver
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $iTimeout
|
||||||
|
*
|
||||||
|
* @return \MailSo\Log\Driver
|
||||||
|
*/
|
||||||
|
public function WriteOnTimeoutOnly($iTimeout)
|
||||||
|
{
|
||||||
|
$this->iWriteOnTimeoutOnly = (int) $iTimeout;
|
||||||
|
if (0 > $this->iWriteOnTimeoutOnly)
|
||||||
|
{
|
||||||
|
$this->iWriteOnTimeoutOnly = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return \MailSo\Log\Driver
|
* @return \MailSo\Log\Driver
|
||||||
*/
|
*/
|
||||||
|
@ -104,7 +126,7 @@ abstract class Driver
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string|array $sDesc
|
* @param string|array $mDesc
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
abstract protected function writeImplementation($mDesc);
|
abstract protected function writeImplementation($mDesc);
|
||||||
|
@ -120,16 +142,16 @@ abstract class Driver
|
||||||
/**
|
/**
|
||||||
* @param string $sTimePrefix
|
* @param string $sTimePrefix
|
||||||
* @param string $sDesc
|
* @param string $sDesc
|
||||||
* @param int $iDescType = \MailSo\Log\Enumerations\Type::INFO
|
* @param int $iType = \MailSo\Log\Enumerations\Type::INFO
|
||||||
* @param array $sName = ''
|
* @param array $sName = ''
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
protected function loggerLineImplementation($sTimePrefix, $sDesc,
|
protected function loggerLineImplementation($sTimePrefix, $sDesc,
|
||||||
$iDescType = \MailSo\Log\Enumerations\Type::INFO, $sName = '')
|
$iType = \MailSo\Log\Enumerations\Type::INFO, $sName = '')
|
||||||
{
|
{
|
||||||
return ($this->bTimePrefix ? '['.$sTimePrefix.'] ' : '').
|
return ($this->bTimePrefix ? '['.$sTimePrefix.'] ' : '').
|
||||||
($this->bTypedPrefix ? $this->getTypedPrefix($iDescType, $sName) : '').
|
($this->bTypedPrefix ? $this->getTypedPrefix($iType, $sName) : '').
|
||||||
$sDesc;
|
$sDesc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -152,46 +174,66 @@ abstract class Driver
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param int $iDescType
|
* @param int $iType
|
||||||
* @param string $sName = ''
|
* @param string $sName = ''
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
protected function getTypedPrefix($iDescType, $sName = '')
|
protected function getTypedPrefix($iType, $sName = '')
|
||||||
{
|
{
|
||||||
$sName = 0 < \strlen($sName) ? $sName : $this->sName;
|
$sName = 0 < \strlen($sName) ? $sName : $this->sName;
|
||||||
return isset($this->aPrefixes[$iDescType]) ? $sName.$this->aPrefixes[$iDescType].': ' : '';
|
return isset($this->aPrefixes[$iType]) ? $sName.$this->aPrefixes[$iType].': ' : '';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @final
|
* @final
|
||||||
* @param string $sDesc
|
* @param string $sDesc
|
||||||
* @param int $iDescType = \MailSo\Log\Enumerations\Type::INFO
|
* @param int $iType = \MailSo\Log\Enumerations\Type::INFO
|
||||||
* @param array $sName = ''
|
* @param string $sName = ''
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
final public function Write($sDesc, $iDescType = \MailSo\Log\Enumerations\Type::INFO, $sName = '')
|
final public function Write($sDesc, $iType = \MailSo\Log\Enumerations\Type::INFO, $sName = '')
|
||||||
{
|
{
|
||||||
if ($this->bWriteOnErrorOnly && !$this->bFlushCache)
|
$bResult = true;
|
||||||
|
if (!$this->bFlushCache && ($this->bWriteOnErrorOnly || 0 < $this->iWriteOnTimeoutOnly))
|
||||||
{
|
{
|
||||||
$this->aCache[] = $this->loggerLineImplementation($this->getTimeWithMicroSec(), $sDesc, $iDescType, $sName);
|
if ($this->bWriteOnErrorOnly && \in_array($iType, array(
|
||||||
|
|
||||||
if (\in_array($iDescType, array(
|
|
||||||
\MailSo\Log\Enumerations\Type::NOTICE,
|
\MailSo\Log\Enumerations\Type::NOTICE,
|
||||||
\MailSo\Log\Enumerations\Type::WARNING,
|
\MailSo\Log\Enumerations\Type::WARNING,
|
||||||
\MailSo\Log\Enumerations\Type::ERROR
|
\MailSo\Log\Enumerations\Type::ERROR
|
||||||
)))
|
)))
|
||||||
{
|
{
|
||||||
$this->bFlushCache = true;
|
$this->aCache[] = $this->loggerLineImplementation($this->getTimeWithMicroSec(), '--- FlushCache: WriteOnErrorOnly', \MailSo\Log\Enumerations\Type::INFO, 'LOGS');
|
||||||
return $this->writeImplementation($this->aCache);
|
$this->aCache[] = $this->loggerLineImplementation($this->getTimeWithMicroSec(), $sDesc, $iType, $sName);
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
$this->bFlushCache = true;
|
||||||
|
$bResult = $this->writeImplementation($this->aCache);
|
||||||
|
$this->aCache = array();
|
||||||
|
}
|
||||||
|
else if (0 < $this->iWriteOnTimeoutOnly && \time() - APP_START_TIME > $this->iWriteOnTimeoutOnly)
|
||||||
|
{
|
||||||
|
$this->aCache[] = $this->loggerLineImplementation($this->getTimeWithMicroSec(), '--- FlushCache: WriteOnTimeoutOnly['.
|
||||||
|
(\time() - APP_START_TIME).'/'.$this->iWriteOnTimeoutOnly.']', \MailSo\Log\Enumerations\Type::NOTE, 'LOGS');
|
||||||
|
|
||||||
|
$this->aCache[] = $this->loggerLineImplementation($this->getTimeWithMicroSec(), $sDesc, $iType, $sName);
|
||||||
|
|
||||||
|
$this->bFlushCache = true;
|
||||||
|
$bResult = $this->writeImplementation($this->aCache);
|
||||||
|
$this->aCache = array();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$this->aCache[] = $this->loggerLineImplementation($this->getTimeWithMicroSec(), $sDesc, $iType, $sName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$bResult = $this->writeImplementation(
|
||||||
|
$this->loggerLineImplementation($this->getTimeWithMicroSec(), $sDesc, $iType, $sName));
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->writeImplementation(
|
return $bResult;
|
||||||
$this->loggerLineImplementation($this->getTimeWithMicroSec(), $sDesc, $iDescType, $sName));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -209,7 +251,7 @@ abstract class Driver
|
||||||
*/
|
*/
|
||||||
final public function WriteEmptyLine()
|
final public function WriteEmptyLine()
|
||||||
{
|
{
|
||||||
if ($this->bWriteOnErrorOnly && !$this->bFlushCache)
|
if (!$this->bFlushCache && ($this->bWriteOnErrorOnly || 0 < $this->iWriteOnTimeoutOnly))
|
||||||
{
|
{
|
||||||
$this->aCache[] = '';
|
$this->aCache[] = '';
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,15 +45,15 @@ class Callback extends \MailSo\Log\Driver
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string|array $sDesc
|
* @param string|array $mDesc
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
protected function writeImplementation($sDesc)
|
protected function writeImplementation($mDesc)
|
||||||
{
|
{
|
||||||
if ($this->fWriteCallback)
|
if ($this->fWriteCallback)
|
||||||
{
|
{
|
||||||
\call_user_func_array($this->fWriteCallback, array($sDesc));
|
\call_user_func_array($this->fWriteCallback, array($mDesc));
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -51,12 +51,12 @@ class Inline extends \MailSo\Log\Driver
|
||||||
*/
|
*/
|
||||||
protected function writeImplementation($mDesc)
|
protected function writeImplementation($mDesc)
|
||||||
{
|
{
|
||||||
if (is_array($mDesc))
|
if (\is_array($mDesc))
|
||||||
{
|
{
|
||||||
if ($this->bHtmlEncodeSpecialChars)
|
if ($this->bHtmlEncodeSpecialChars)
|
||||||
{
|
{
|
||||||
$mDesc = array_map(function ($sItem) {
|
$mDesc = \array_map(function ($sItem) {
|
||||||
$sItem = \htmlspecialchars($mDesc);
|
return \htmlspecialchars($sItem);
|
||||||
}, $mDesc);
|
}, $mDesc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -83,7 +83,7 @@ class Logger extends \MailSo\Base\Collection
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param int $iDescType
|
* @param int $iType
|
||||||
*
|
*
|
||||||
* @return \MailSo\Log\Logger
|
* @return \MailSo\Log\Logger
|
||||||
*/
|
*/
|
||||||
|
@ -95,7 +95,7 @@ class Logger extends \MailSo\Base\Collection
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param int $iDescType
|
* @param int $iType
|
||||||
*
|
*
|
||||||
* @return \MailSo\Log\Logger
|
* @return \MailSo\Log\Logger
|
||||||
*/
|
*/
|
||||||
|
@ -141,15 +141,15 @@ class Logger extends \MailSo\Base\Collection
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $sDesc
|
* @param string $sDesc
|
||||||
* @param int $iDescType = \MailSo\Log\Enumerations\Type::INFO
|
* @param int $iType = \MailSo\Log\Enumerations\Type::INFO
|
||||||
* @param string $sName = ''
|
* @param string $sName = ''
|
||||||
* @param bool $bSearchWords = false
|
* @param bool $bSearchWords = false
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function Write($sDesc, $iDescType = \MailSo\Log\Enumerations\Type::INFO, $sName = '', $bSearchWords = false)
|
public function Write($sDesc, $iType = \MailSo\Log\Enumerations\Type::INFO, $sName = '', $bSearchWords = false)
|
||||||
{
|
{
|
||||||
if (isset($this->aForbiddenTypes[$iDescType]) && true === $this->aForbiddenTypes[$iDescType])
|
if (isset($this->aForbiddenTypes[$iType]) && true === $this->aForbiddenTypes[$iType])
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -168,7 +168,7 @@ class Logger extends \MailSo\Base\Collection
|
||||||
$aLoggers =& $this->GetAsArray();
|
$aLoggers =& $this->GetAsArray();
|
||||||
foreach ($aLoggers as /* @var $oLogger \MailSo\Log\Driver */ $oLogger)
|
foreach ($aLoggers as /* @var $oLogger \MailSo\Log\Driver */ $oLogger)
|
||||||
{
|
{
|
||||||
$iResult &= $oLogger->Write($sDesc, $iDescType, $sName);
|
$iResult &= $oLogger->Write($sDesc, $iType, $sName);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (bool) $iResult;
|
return (bool) $iResult;
|
||||||
|
@ -176,26 +176,26 @@ class Logger extends \MailSo\Base\Collection
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param mixed $oValue
|
* @param mixed $oValue
|
||||||
* @param int $iDescType = \MailSo\Log\Enumerations\Type::INFO
|
* @param int $iType = \MailSo\Log\Enumerations\Type::INFO
|
||||||
* @param string $sName = ''
|
* @param string $sName = ''
|
||||||
* @param bool $bSearchSecretWords = false
|
* @param bool $bSearchSecretWords = false
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function WriteDump($oValue, $iDescType = \MailSo\Log\Enumerations\Type::INFO, $sName = '', $bSearchSecretWords = false)
|
public function WriteDump($oValue, $iType = \MailSo\Log\Enumerations\Type::INFO, $sName = '', $bSearchSecretWords = false)
|
||||||
{
|
{
|
||||||
return $this->Write(\print_r($oValue, true), $iDescType, $sName, $bSearchSecretWords);
|
return $this->Write(\print_r($oValue, true), $iType, $sName, $bSearchSecretWords);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param \Exception $oException
|
* @param \Exception $oException
|
||||||
* @param int $iDescType = \MailSo\Log\Enumerations\Type::NOTICE
|
* @param int $iType = \MailSo\Log\Enumerations\Type::NOTICE
|
||||||
* @param string $sName = ''
|
* @param string $sName = ''
|
||||||
* @param bool $bSearchSecretWords = true
|
* @param bool $bSearchSecretWords = true
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function WriteException($oException, $iDescType = \MailSo\Log\Enumerations\Type::NOTICE, $sName = '', $bSearchSecretWords = true)
|
public function WriteException($oException, $iType = \MailSo\Log\Enumerations\Type::NOTICE, $sName = '', $bSearchSecretWords = true)
|
||||||
{
|
{
|
||||||
if ($oException instanceof \Exception)
|
if ($oException instanceof \Exception)
|
||||||
{
|
{
|
||||||
|
@ -206,28 +206,28 @@ class Logger extends \MailSo\Base\Collection
|
||||||
|
|
||||||
$oException->__LOGINNED__ = true;
|
$oException->__LOGINNED__ = true;
|
||||||
|
|
||||||
return $this->Write((string) $oException, $iDescType, $sName, $bSearchSecretWords);
|
return $this->Write((string) $oException, $iType, $sName, $bSearchSecretWords);
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param \Exception $oException
|
* @param mixed $mData
|
||||||
* @param int $iDescType = \MailSo\Log\Enumerations\Type::NOTICE
|
* @param int $iType = \MailSo\Log\Enumerations\Type::NOTICE
|
||||||
* @param string $sName = ''
|
* @param string $sName = ''
|
||||||
* @param bool $bSearchSecretWords = true
|
* @param bool $bSearchSecretWords = true
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function WriteMixed($mData, $iDescType = null, $sName = '', $bSearchSecretWords = true)
|
public function WriteMixed($mData, $iType = null, $sName = '', $bSearchSecretWords = true)
|
||||||
{
|
{
|
||||||
$iType = null === $iDescType ? \MailSo\Log\Enumerations\Type::INFO : $iDescType;
|
$iType = null === $iType ? \MailSo\Log\Enumerations\Type::INFO : $iType;
|
||||||
if (\is_array($mData) || \is_object($mData))
|
if (\is_array($mData) || \is_object($mData))
|
||||||
{
|
{
|
||||||
if ($mData instanceof \Exception)
|
if ($mData instanceof \Exception)
|
||||||
{
|
{
|
||||||
$iType = null === $iDescType ? \MailSo\Log\Enumerations\Type::NOTICE : $iType;
|
$iType = null === $iType ? \MailSo\Log\Enumerations\Type::NOTICE : $iType;
|
||||||
return $this->WriteException($mData, $iType, $sName, $bSearchSecretWords);
|
return $this->WriteException($mData, $iType, $sName, $bSearchSecretWords);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
@ -758,8 +758,11 @@ class Actions
|
||||||
@mkdir($sLogFileDir, 0755, true);
|
@mkdir($sLogFileDir, 0755, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->oLogger->Add(\MailSo\Log\Drivers\File::NewInstance($sLogFileFullPath)
|
$this->oLogger->Add(
|
||||||
->WriteOnErrorOnly($this->Config()->Get('logs', 'write_on_error_only', true)));
|
\MailSo\Log\Drivers\File::NewInstance($sLogFileFullPath)
|
||||||
|
->WriteOnErrorOnly($this->Config()->Get('logs', 'write_on_error_only', true))
|
||||||
|
->WriteOnTimeoutOnly($this->Config()->Get('logs', 'write_on_timeout_only', 30))
|
||||||
|
);
|
||||||
|
|
||||||
if (!$this->Config()->Get('debug', 'enable', false))
|
if (!$this->Config()->Get('debug', 'enable', false))
|
||||||
{
|
{
|
||||||
|
@ -3866,6 +3869,7 @@ class Actions
|
||||||
*/
|
*/
|
||||||
public function DoMessageList()
|
public function DoMessageList()
|
||||||
{
|
{
|
||||||
|
// sleep(5);
|
||||||
// throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::CantGetMessageList);
|
// throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::CantGetMessageList);
|
||||||
|
|
||||||
$sFolder = '';
|
$sFolder = '';
|
||||||
|
|
|
@ -142,6 +142,7 @@ Values:
|
||||||
'enable' => array(false, 'Enable logging'),
|
'enable' => array(false, 'Enable logging'),
|
||||||
|
|
||||||
'write_on_error_only' => array(false, 'Logs entire request only if error occured'),
|
'write_on_error_only' => array(false, 'Logs entire request only if error occured'),
|
||||||
|
'write_on_timeout_only' => array(0, 'Logs entire request only if request timeout (in seconds) occured.'),
|
||||||
|
|
||||||
'filename' => array('log-{date:Y-m-d}.txt',
|
'filename' => array('log-{date:Y-m-d}.txt',
|
||||||
'Log filename.
|
'Log filename.
|
||||||
|
|
|
@ -3,8 +3,10 @@
|
||||||
if (defined('APP_VERSION'))
|
if (defined('APP_VERSION'))
|
||||||
{
|
{
|
||||||
define('APP_START', microtime(true));
|
define('APP_START', microtime(true));
|
||||||
define('APP_INDEX_FILE', 'index.php');
|
define('APP_START_TIME', time());
|
||||||
|
define('APP_REQUEST_RND', md5(APP_START.rand(10000, 99999).APP_START));
|
||||||
define('APP_VERSION_ROOT_PATH', APP_INDEX_ROOT_PATH.'rainloop/v/'.APP_VERSION.'/');
|
define('APP_VERSION_ROOT_PATH', APP_INDEX_ROOT_PATH.'rainloop/v/'.APP_VERSION.'/');
|
||||||
|
define('APP_INDEX_FILE', 'index.php');
|
||||||
|
|
||||||
if (function_exists('date_default_timezone_set'))
|
if (function_exists('date_default_timezone_set'))
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue