Fix time_offset setting (#1241)

This commit is contained in:
RainLoop Team 2016-10-27 22:51:38 +03:00
parent 7e135b10ac
commit 022ed24c2a
6 changed files with 1345 additions and 1310 deletions

View file

@ -120,4 +120,35 @@ class DateTimeHelper
return \MailSo\Base\DateTimeHelper::ParseDateStringType1($sDateTime); return \MailSo\Base\DateTimeHelper::ParseDateStringType1($sDateTime);
} }
/**
* @param string $sTime
*
* @return int
*/
public static function TimeToSec($sTime)
{
$iMod = 1;
$sTime = \trim($sTime);
if ('-' === \substr($sTime, 0, 1))
{
$iMod = -1;
$sTime = \substr($sTime, 1);
}
$aParts = \preg_split('/[:.,]/', (string) $sTime);
$iResult = 0;
if (isset($aParts[0]) && \is_numeric($aParts[0]))
{
$iResult += 3600 * ((int) $aParts[0]);
}
if (isset($aParts[1]) && \is_numeric($aParts[1]))
{
$iResult += 60 * ((int) $aParts[1]);
}
return $iResult * $iMod;
}
} }

View file

@ -37,6 +37,11 @@ abstract class Driver
*/ */
protected $bGuidPrefix; protected $bGuidPrefix;
/**
* @var string
*/
protected $sTimeOffset;
/** /**
* @var bool * @var bool
*/ */
@ -89,7 +94,7 @@ abstract class Driver
$this->bTypedPrefix = true; $this->bTypedPrefix = true;
$this->bGuidPrefix = true; $this->bGuidPrefix = true;
$this->iTimeOffset = 0; $this->sTimeOffset = '0';
$this->iWriteOnTimeoutOnly = 0; $this->iWriteOnTimeoutOnly = 0;
$this->bWriteOnErrorOnly = false; $this->bWriteOnErrorOnly = false;
@ -115,13 +120,13 @@ abstract class Driver
} }
/** /**
* @param int $iTimeOffset * @param string $sTimeOffset
* *
* @return \MailSo\Log\Driver * @return \MailSo\Log\Driver
*/ */
public function SetTimeOffset($iTimeOffset) public function SetTimeOffset($sTimeOffset)
{ {
$this->iTimeOffset = $iTimeOffset; $this->sTimeOffset = (string) $sTimeOffset;
return $this; return $this;
} }
@ -236,7 +241,7 @@ abstract class Driver
protected function getTimeWithMicroSec() protected function getTimeWithMicroSec()
{ {
$aMicroTimeItems = \explode(' ', \microtime()); $aMicroTimeItems = \explode(' ', \microtime());
return \MailSo\Log\Logger::DateHelper($this->sDatePattern, $this->iTimeOffset, $aMicroTimeItems[1]).'.'. return \MailSo\Log\Logger::DateHelper($this->sDatePattern, $this->sTimeOffset, $aMicroTimeItems[1]).'.'.
\str_pad((int) ($aMicroTimeItems[0] * 1000), 3, '0', STR_PAD_LEFT); \str_pad((int) ($aMicroTimeItems[0] * 1000), 3, '0', STR_PAD_LEFT);
} }

View file

@ -93,17 +93,15 @@ class Logger extends \MailSo\Base\Collection
/** /**
* @param string $sFormat * @param string $sFormat
* @param int $iTimeOffset = 0 * @param string $sTimeOffset = '0'
* @param int $iTimestamp = 0 * @param int $iTimestamp = 0
* *
* @return string * @return string
*/ */
public static function DateHelper($sFormat, $iTimeOffset = 0, $iTimestamp = null) public static function DateHelper($sFormat, $sTimeOffset = '0', $iTimestamp = null)
{ {
$iTimestamp = null === $iTimestamp ? \time() : (int) $iTimestamp; $iTimestamp = null === $iTimestamp ? \time() : (int) $iTimestamp;
$iTimeOffset = (int) $iTimeOffset; return \gmdate($sFormat, $iTimestamp + \MailSo\Base\DateTimeHelper::TimeToSec((string) $sTimeOffset));
return \gmdate($sFormat, $iTimestamp + $iTimeOffset * 3600);
} }
/** /**

View file

@ -430,9 +430,9 @@ class Actions
if (false !== \strpos($sLine, '{date:')) if (false !== \strpos($sLine, '{date:'))
{ {
$iTimeOffset = (int) $this->Config()->Get('logs', 'time_offset', 0); $sTimeOffset = (string) $this->Config()->Get('logs', 'time_offset', '0');
$sLine = \preg_replace_callback('/\{date:([^}]+)\}/', function ($aMatch) use ($iTimeOffset, $bUrlEncode) { $sLine = \preg_replace_callback('/\{date:([^}]+)\}/', function ($aMatch) use ($sTimeOffset, $bUrlEncode) {
return \RainLoop\Utils::UrlEncode(\MailSo\Log\Logger::DateHelper($aMatch[1], $iTimeOffset), $bUrlEncode); return \RainLoop\Utils::UrlEncode(\MailSo\Log\Logger::DateHelper($aMatch[1], $sTimeOffset), $bUrlEncode);
}, $sLine); }, $sLine);
$aClear['/\{date:([^}]*)\}/'] = 'date'; $aClear['/\{date:([^}]*)\}/'] = 'date';
@ -1073,7 +1073,7 @@ class Actions
} }
} }
$iTimeOffset = (int) $this->Config()->Get('logs', 'time_offset', 0); $sTimeOffset = (string) $this->Config()->Get('logs', 'time_offset', '0');
$this->oLogger->SetShowSecter(!$this->Config()->Get('logs', 'hide_passwords', true)); $this->oLogger->SetShowSecter(!$this->Config()->Get('logs', 'hide_passwords', true));
@ -1101,7 +1101,7 @@ class Actions
->WriteOnErrorOnly($this->Config()->Get('logs', 'write_on_error_only', false)) ->WriteOnErrorOnly($this->Config()->Get('logs', 'write_on_error_only', false))
->WriteOnPhpErrorOnly($this->Config()->Get('logs', 'write_on_php_error_only', false)) ->WriteOnPhpErrorOnly($this->Config()->Get('logs', 'write_on_php_error_only', false))
->WriteOnTimeoutOnly($this->Config()->Get('logs', 'write_on_timeout_only', 0)) ->WriteOnTimeoutOnly($this->Config()->Get('logs', 'write_on_timeout_only', 0))
->SetTimeOffset($iTimeOffset) ->SetTimeOffset($sTimeOffset)
); );
if (!$this->Config()->Get('debug', 'enable', false)) if (!$this->Config()->Get('debug', 'enable', false))
@ -1113,9 +1113,9 @@ class Actions
$oHttp = $this->Http(); $oHttp = $this->Http();
$this->oLogger->Write('[DATE:'.\MailSo\Log\Logger::DateHelper('d.m.y', $iTimeOffset). $this->oLogger->Write('[DATE:'.\MailSo\Log\Logger::DateHelper('d.m.y', $sTimeOffset).
(0 !== $iTimeOffset ? '][OFFSET:'.(0 < $iTimeOffset ? '+' : '-'). (0 !== $sTimeOffset ? '][OFFSET:'.(0 < $sTimeOffset ? '+' : '-').
\str_pad((string) \abs($iTimeOffset), 2, '0', STR_PAD_LEFT) : ''). \str_pad((string) \abs($sTimeOffset), 2, '0', STR_PAD_LEFT) : '').
'][RL:'.APP_VERSION.'][PHP:'.PHP_VERSION.'][IP:'. '][RL:'.APP_VERSION.'][PHP:'.PHP_VERSION.'][IP:'.
$oHttp->GetClientIp($this->Config()->Get('labs', 'http_client_ip_check_proxy', false)).'][PID:'. $oHttp->GetClientIp($this->Config()->Get('labs', 'http_client_ip_check_proxy', false)).'][PID:'.
(\MailSo\Base\Utils::FunctionExistsAndEnabled('getmypid') ? \getmypid() : 'unknown').']['. (\MailSo\Base\Utils::FunctionExistsAndEnabled('getmypid') ? \getmypid() : 'unknown').']['.

View file

@ -97,6 +97,7 @@ abstract class AbstractConfig
switch ($sType) switch ($sType)
{ {
default: default:
case 'float':
case 'string': case 'string':
$this->aData[$sSectionKey][$sParamKey][0] = (string) $mParamValue; $this->aData[$sSectionKey][$sParamKey][0] = (string) $mParamValue;
break; break;

View file

@ -293,7 +293,7 @@ Values:
'hide_passwords' => array(true, 'Required for development purposes only. 'hide_passwords' => array(true, 'Required for development purposes only.
Disabling this option is not recommended.'), Disabling this option is not recommended.'),
'time_offset' => array(0), 'time_offset' => array('0'),
'session_filter' => array(''), 'session_filter' => array(''),
'filename' => array('log-{date:Y-m-d}.txt', 'filename' => array('log-{date:Y-m-d}.txt',