From 5ed3e7dc937463e459202a4a318d5c4daada50a4 Mon Sep 17 00:00:00 2001 From: at15 Date: Tue, 10 Jan 2017 21:43:36 -0800 Subject: [PATCH] Remove miniTS in TextFormatter - Related issues: https://github.com/sirupsen/logrus/issues/457 - miniTS use current time instead of time the log function is called, which is inaccurate when hook takes a long time - `miniTS` is removed and replaced by `int(entry.Time.Sub(baseTimestamp)/time.Second)` in `printColored` which is the only usage of `miniTS` --- text_formatter.go | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/text_formatter.go b/text_formatter.go index 20f2d7e..dd86caa 100644 --- a/text_formatter.go +++ b/text_formatter.go @@ -28,10 +28,6 @@ func init() { isTerminal = IsTerminal() } -func miniTS() int { - return int(time.Since(baseTimestamp) / time.Second) -} - type TextFormatter struct { // Set to true to bypass checking for a TTY before outputting colors. ForceColors bool @@ -118,7 +114,7 @@ func (f *TextFormatter) printColored(b *bytes.Buffer, entry *Entry, keys []strin if f.DisableTimestamp { fmt.Fprintf(b, "\x1b[%dm%s\x1b[0m %-44s ", levelColor, levelText, entry.Message) } else if !f.FullTimestamp { - fmt.Fprintf(b, "\x1b[%dm%s\x1b[0m[%04d] %-44s ", levelColor, levelText, miniTS(), entry.Message) + fmt.Fprintf(b, "\x1b[%dm%s\x1b[0m[%04d] %-44s ", levelColor, levelText, int(entry.Time.Sub(baseTimestamp)/time.Second), entry.Message) } else { fmt.Fprintf(b, "\x1b[%dm%s\x1b[0m[%s] %-44s ", levelColor, levelText, entry.Time.Format(timestampFormat), entry.Message) }