From a3c0c63d65aa21fcf49ce83b4703fc87eb6ae228 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Tue, 4 Jul 2017 14:56:51 +0200 Subject: [PATCH] use the correct timezone when parsing log times Signed-off-by: Robin Appelman --- lib/Controller/LogController.php | 3 ++- lib/Log/LogIterator.php | 12 +++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/Controller/LogController.php b/lib/Controller/LogController.php index 6f5b150d2..4a97e25f5 100644 --- a/lib/Controller/LogController.php +++ b/lib/Controller/LogController.php @@ -49,12 +49,13 @@ public function __construct($appName, private function getLogIterator() { $dateFormat = $this->config->getSystemValue('logdateformat', \DateTime::ATOM); + $timezone = $this->config->getSystemValue('logtimezone', 'UTC'); $logClasses = ['\OC\Log\Owncloud', '\OC_Log_Owncloud', '\OC\Log\File']; foreach ($logClasses as $logClass) { if (class_exists($logClass)) { $handle = fopen($logClass::getLogFilePath(), 'rb'); if ($handle) { - return new LogIterator($handle, $dateFormat); + return new LogIterator($handle, $dateFormat, $timezone); } else { throw new \Exception("Error while opening ".$logClass::getLogFilePath()); } diff --git a/lib/Log/LogIterator.php b/lib/Log/LogIterator.php index a4ac4d5a6..4d7f70847 100644 --- a/lib/Log/LogIterator.php +++ b/lib/Log/LogIterator.php @@ -49,15 +49,19 @@ class LogIterator implements \Iterator { */ private $dateFormat; + private $timezone; + const CHUNK_SIZE = 100; // how many chars do we try at once to find a new line /** * @param resource $handle * @param string $dateFormat + * @param string $timezone */ - public function __construct($handle, $dateFormat) { + public function __construct($handle, $dateFormat, $timezone) { $this->handle = $handle; $this->dateFormat = $dateFormat; + $this->timezone = new \DateTimeZone($timezone); $this->rewind(); $this->next(); } @@ -71,8 +75,10 @@ function rewind() { function current() { $entry = json_decode($this->lastLine, true); if ($this->dateFormat !== \DateTime::ATOM) { - $time = \DateTime::createFromFormat($this->dateFormat, $entry['time']); - $entry['time'] = $time->format(\DateTime::ATOM); + $time = \DateTime::createFromFormat($this->dateFormat, $entry['time'], $this->timezone); + if ($time) { + $entry['time'] = $time->format(\DateTime::ATOM); + } } return $entry; }