From ceb2a1fc8af2b4521b65d55c4e972268d4cb3888 Mon Sep 17 00:00:00 2001 From: Tom Coupland Date: Wed, 17 Oct 2018 16:17:00 +0100 Subject: [PATCH] Configure logrus to include nano seconds in log messages (#1273) Currently the default time format, time.RFC3339, is used, which doesn't include any subsecond resolution information. This makes it hard to understand the ordering of log messages when viewing in a log aggregator, like Kibana. This change sets the TimestampFormat of the logrus JSONFormatter to time.RFC3339Nano. --- api/common/logging.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/api/common/logging.go b/api/common/logging.go index a482a48d5..2e9128fc9 100644 --- a/api/common/logging.go +++ b/api/common/logging.go @@ -3,10 +3,11 @@ package common import ( "net/url" "os" + "strings" + "time" "github.com/gin-gonic/gin" "github.com/sirupsen/logrus" - "strings" ) func SetLogFormat(format string) { @@ -15,7 +16,7 @@ func SetLogFormat(format string) { } if format == "json" { - logrus.SetFormatter(&logrus.JSONFormatter{}) + logrus.SetFormatter(&logrus.JSONFormatter{TimestampFormat: time.RFC3339Nano}) } else { // show full timestamps formatter := &logrus.TextFormatter{