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

Override the timestamp key used in zerolog #47

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions cobrazerolog/cobrazerolog.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ import (
"github.com/spf13/pflag"
)

func init() {
// override the `time` field name to not conflict with other existing `time` fields
// in logs.
// See: https://github.com/rs/zerolog/blob/1f50797d7d24e4cf3a6407203bd694f3d35de724/event.go#L643
zerolog.TimestampFieldName = "log-timestamp"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be in init or New? I could see someone importing this library in the future while not desiring this side affect.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was my question: or should it be a function we export from here that the importer calls?

}

// Option is function used to configure Zerolog within a Cobra RunFunc.
type Option func(*Builder)

Expand Down