Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change trace duration to milliseconds #76

Open
tj opened this issue Oct 29, 2019 · 2 comments
Open

Change trace duration to milliseconds #76

tj opened this issue Oct 29, 2019 · 2 comments

Comments

@tj
Copy link
Member

tj commented Oct 29, 2019

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
Copy link

mhemmings commented May 21, 2020

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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants