TimeFormat can lead to misaligned output
Closed this issue · 2 comments
ammario commented
E.g if I use
logOpts := &tint.Options{
AddSource: true,
Level: slog.LevelDebug,
TimeFormat: time.Kitchen + " 05.999",
}
I can end up with logs like:
3:36PM 44.098 DBG labeler/indexer.go:244 indexed issue repo=coder/code-server num=3031
3:36PM 44.35 DBG labeler/indexer.go:244 indexed issue repo=coder/code-server num=3029
One possible solution is accepting the width of the time column via tint.Options. The better solution, I think, is allowing a callback to generate the time string. E.g.:
NowFn: func() string {
timeFormatted := t.Format(time.Kitchen)
milliseconds := t.Nanosecond() / 1e6
return timeFormatted + fmt.Sprintf(" %03d", milliseconds)
}
lmittmann commented
Might fix your issue: https://stackoverflow.com/a/47165010/10595796
ammario commented
Ah, I missed that. Thank you the prompt response.