From be47984c430b866377f1e86ff2354e8e88215d69 Mon Sep 17 00:00:00 2001 From: Robert Swain Date: Thu, 20 Apr 2017 17:15:30 +0200 Subject: [PATCH] common/log: Always output timestamps as UTC --- .../matrix-org/dendrite/common/log.go | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/github.com/matrix-org/dendrite/common/log.go b/src/github.com/matrix-org/dendrite/common/log.go index 625ef20a..6bed9c9a 100644 --- a/src/github.com/matrix-org/dendrite/common/log.go +++ b/src/github.com/matrix-org/dendrite/common/log.go @@ -8,13 +8,24 @@ import ( "github.com/matrix-org/dugong" ) +type utcFormatter struct { + logrus.Formatter +} + +func (f utcFormatter) Format(entry *logrus.Entry) ([]byte, error) { + entry.Time = entry.Time.UTC() + return f.Formatter.Format(entry) +} + // SetupLogging configures the logging format and destination(s). func SetupLogging(logDir string) { - formatter := &logrus.TextFormatter{ - TimestampFormat: "2006-01-02T15:04:05.000000000Z07:00", - DisableColors: true, - DisableTimestamp: false, - DisableSorting: false, + formatter := &utcFormatter{ + &logrus.TextFormatter{ + TimestampFormat: "2006-01-02T15:04:05.000000000Z07:00", + DisableColors: true, + DisableTimestamp: false, + DisableSorting: false, + }, } if logDir != "" { _ = os.Mkdir(logDir, os.ModePerm)