Open bojanz opened 4 years ago
I'm using a terminal with a "Solarized" color scheme and the timestamp seems to be exactly in the background color and thus not visible at all.
could we disable color on timestamp field? It's really hard to read on dark background terminal
confusing that this is still open. is it a WONTFIX?
It’s a won’t fix by itself :)
@rs Happy to send in a PR if you agree with the proposed fix (stop coloring the timestamp).
Go ahead
the default timestamp Formatter implementation is written in here
we can write our own Formatter to disable color
func main() {
consoloLog := zerolog.NewConsoleWriter(func(w *zerolog.ConsoleWriter) {
w.FormatTimestamp = consoleFormatTimestamp(w.TimeFormat)
})
}
func consoleFormatTimestamp(timeFormat string) zerolog.Formatter {
return func(i interface{}) string {
t := "<nil>"
switch tt := i.(type) {
case string:
ts, err := time.Parse(zerolog.TimeFieldFormat, tt)
if err != nil {
t = tt
} else {
t = ts.Format(timeFormat)
}
case json.Number:
i, err := tt.Int64()
if err != nil {
t = tt.String()
} else {
var sec, nsec int64 = i, 0
switch zerolog.TimeFieldFormat {
case zerolog.TimeFormatUnixMs:
nsec = int64(time.Duration(i) * time.Millisecond)
sec = 0
case zerolog.TimeFormatUnixMicro:
nsec = int64(time.Duration(i) * time.Microsecond)
sec = 0
}
ts := time.Unix(sec, nsec).UTC()
t = ts.Format(timeFormat)
}
}
return t
}
}
I use a non-customized zsh + Pure terminal. Pure has a dark background color, making the ConsoleWriter's timestamp color hard to read: https://www.dropbox.com/s/qdj9t1plv977s4g/zerolog%20terminal.png?dl=0
This was introduced in #131.
Could I suggest not coloring the timestamp at all, like Zap does? After all, the primary goal for the coloring logic is to differentiate the levels.