log icon indicating copy to clipboard operation
log copied to clipboard

Change trace duration to milliseconds

Open tj opened this issue 6 years ago • 2 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.

tj avatar Oct 29 '19 12:10 tj

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.

mhemmings avatar May 21 '20 22:05 mhemmings

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

JeffFaer avatar Feb 21 '22 01:02 JeffFaer