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.
This commit is contained in:
Tom Coupland
2018-10-17 16:17:00 +01:00
committed by GitHub
parent f84ae832b7
commit ceb2a1fc8a

View File

@@ -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{