diff --git a/pkg/logger/logger.go b/pkg/logger/logger.go index d0e905b4e..a1ccc9c44 100644 --- a/pkg/logger/logger.go +++ b/pkg/logger/logger.go @@ -6,11 +6,22 @@ package logger import ( + "time" + "github.com/sirupsen/logrus" prefixed "github.com/x-cray/logrus-prefixed-formatter" "gopkg.in/natefinch/lumberjack.v2" ) +type TZFormatter struct { + logrus.Formatter +} + +func (u TZFormatter) Format(e *logrus.Entry) ([]byte, error) { + e.Time = time.Now() + return u.Formatter.Format(e) +} + func NewLogger(logLevel string, disableTimestamp bool, logFileOpt *lumberjack.Logger) *logrus.Logger { log := logrus.New() @@ -20,11 +31,11 @@ func NewLogger(logLevel string, disableTimestamp bool, logFileOpt *lumberjack.Lo } log.SetLevel(level) - log.SetFormatter(&prefixed.TextFormatter{ + log.SetFormatter(TZFormatter{&prefixed.TextFormatter{ DisableTimestamp: disableTimestamp, FullTimestamp: true, TimestampFormat: "Jan 02 15:04:05", - }) + }}) if logFileOpt != nil { log.SetOutput(logFileOpt) } diff --git a/pkg/logger/logger_test.go b/pkg/logger/logger_test.go new file mode 100644 index 000000000..8873b698e --- /dev/null +++ b/pkg/logger/logger_test.go @@ -0,0 +1,13 @@ +package logger + +import ( + "testing" + + "gopkg.in/natefinch/lumberjack.v2" +) + +func TestLogger(t *testing.T) { + var logOpts *lumberjack.Logger + log := NewLogger("debug", false, logOpts) + log.Info("Hi there!") +}