Change trace duration to milliseconds
tj opened this issue · comments
I think nanoseconds is far too much granularity for the average use-case, I've never had a problem with millisecond resolution, but it's a breaking change.
Yeah milliseconds make much more sense. I was thinking maybe to allow this without it being a breaking change, the duration unit could be on the Logger?
e.g.
type Logger struct {
Handler Handler
Level Level
TraceUnit time.Duration
}
Then:
func (e *Entry) Stop(err *error) {
duration := int64(time.Since(e.start) / e.Logger.TraceUnit)
if err == nil || *err == nil {
e.WithField("duration", duration).Info(e.Message)
} else {
e.WithField("duration", duration).WithError(*err).Error(e.Message)
}
}
Can log in any duration you wish then (there will be occasional times where seconds is suitable) but still use nanoseconds by default.
Just poking through this repo. Looks like this was originally done in d1cd28b, and it still seems to be the case today:
https://github.com/apex/log/blob/v1.9.0/entry.go#L154
https://github.com/apex/log/blob/v1.9.0/entry.go#L53