From 659fc9101a384a84b32d943359b1be59bd4038d8 Mon Sep 17 00:00:00 2001 From: Alexander Tesfamichael Date: Thu, 5 Oct 2023 16:40:05 +0100 Subject: [PATCH] feat(logging): log timestamps in RFC3339Milli - Changes the timestamp format to human-readable RFC3339. - Increases the precision to millisecond from second. --- common/logging.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/common/logging.go b/common/logging.go index 117f0a89..183614c7 100644 --- a/common/logging.go +++ b/common/logging.go @@ -6,15 +6,22 @@ import ( "github.com/sirupsen/logrus" ) +// RFC3339Milli is a RFC3339 timestamp format restricted to millisecond precision. +// No standard format is provided, so we create our own. +const RFC3339Milli = "2006-01-02T15:04:05.000Z07:00" + func LogSetup(json bool, logLevel string) *logrus.Entry { log := logrus.NewEntry(logrus.New()) log.Logger.SetOutput(os.Stdout) if json { - log.Logger.SetFormatter(&logrus.JSONFormatter{}) + log.Logger.SetFormatter(&logrus.JSONFormatter{ + TimestampFormat: RFC3339Milli, + }) } else { log.Logger.SetFormatter(&logrus.TextFormatter{ - FullTimestamp: true, + TimestampFormat: RFC3339Milli, + FullTimestamp: true, }) }