From 6095a47acbeb21d7a4940130b462449c87f097f7 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Fri, 11 Oct 2013 14:57:36 +0200 Subject: [PATCH] let admin specify timezone for log file entries Backport from #5173 and #5219 --- config/config.sample.php | 5 ++++- lib/log/owncloud.php | 12 ++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/config/config.sample.php b/config/config.sample.php index 5c09269ea3c..092480d4f5d 100644 --- a/config/config.sample.php +++ b/config/config.sample.php @@ -181,5 +181,8 @@ $CONFIG = array( 'customclient_ios' => '', //https://itunes.apple.com/us/app/owncloud/id543672169?mt=8 // date format to be used while writing to the owncloud logfile -'logdateformat' => 'F d, Y H:i:s' +'logdateformat' => 'F d, Y H:i:s', + +/* timezone used while writing to the owncloud logfile (default: UTC) */ +'logtimezone' => 'Europe/Berlin', ); diff --git a/lib/log/owncloud.php b/lib/log/owncloud.php index d16b9537a16..53e98817902 100644 --- a/lib/log/owncloud.php +++ b/lib/log/owncloud.php @@ -51,8 +51,16 @@ class OC_Log_Owncloud { if($level>=$minLevel) { // default to ISO8601 $format = OC_Config::getValue('logdateformat', 'c'); - $time = date($format, time()); - $entry=array('app'=>$app, 'message'=>$message, 'level'=>$level, 'time'=> $time); + $logtimezone=OC_Config::getValue( "logtimezone", 'UTC' ); + try { + $timezone = new DateTimeZone($logtimezone); + } catch (Exception $e) { + $timezone = new DateTimeZone('UTC'); + } + $time = new DateTime(null, $timezone); + $entry=array('app'=>$app, 'message'=>$message, 'level'=>$level, 'time'=> $time->format($format)); + + $handle = @fopen(self::$logFile, 'a'); if ($handle) { fwrite($handle, json_encode($entry)."\n"); -- 2.39.5