apex / log

Structured logging package for Go.
MIT License
1.37k stars 112 forks source link

Change trace duration to milliseconds #76

Open tj opened 5 years ago

tj commented 5 years ago

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.

mhemmings commented 4 years ago

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.

JeffFaer commented 2 years ago

Just poking through this repo. Looks like this was originally done in https://github.com/apex/log/commit/d1cd28bae5c4ede2cd78119e562f9675b3a4e597, 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