From c73f47f2d8e98589febbff99097d521f3699e0a8 Mon Sep 17 00:00:00 2001 From: Justin Reagor Date: Fri, 5 Jan 2018 15:10:40 -0500 Subject: [PATCH] Introduce configurable timestamp format ala Logrus practices --- config/logger/logging.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/config/logger/logging.go b/config/logger/logging.go index 3b363556..3b553b5e 100644 --- a/config/logger/logging.go +++ b/config/logger/logging.go @@ -59,7 +59,9 @@ func (l *Config) Init() error { case "json": formatter = &logrus.JSONFormatter{} case "default": - formatter = &DefaultLogFormatter{} + formatter = &DefaultLogFormatter{ + TimestampFormat: time.RFC3339Nano, + } default: return fmt.Errorf("Unknown log format '%s'", l.Format) } @@ -86,13 +88,14 @@ func (l *Config) Init() error { // DefaultLogFormatter delegates formatting to standard go log package type DefaultLogFormatter struct { + TimestampFormat string } // Format formats the logrus entry by passing it to the "log" package func (f *DefaultLogFormatter) Format(entry *logrus.Entry) ([]byte, error) { b := &bytes.Buffer{} logger := log.New(b, "", 0) - logger.Println(time.Now().Format(time.RFC3339Nano) + " " + string(entry.Message)) + logger.Println(time.Now().Format(f.TimestampFormat) + " " + string(entry.Message)) // Panic and Fatal are handled by logrus automatically return b.Bytes(), nil }