Skip to content

Improve logging with zerolog#19

Merged
statik merged 2 commits intomainfrom
zerolog
May 17, 2021
Merged

Improve logging with zerolog#19
statik merged 2 commits intomainfrom
zerolog

Conversation

@statik
Copy link
Member

@statik statik commented May 17, 2021

Now log messages are structured json if not on tty, on tty colored output. Log messages include source file location and more consistent error extraction. Using zero allocation logger package.

statik added 2 commits May 16, 2021 22:07
Signed-off-by: Elliot Murphy <statik@users.noreply.github.com>
Signed-off-by: Elliot Murphy <statik@users.noreply.github.com>
formattedJSON, err := json.MarshalIndent(data, "", " ")
if err != nil {
log.Fatal(err)
log.Fatal().Err(err).Msg("Trouble marshalling to JSON")
Copy link
Contributor

Choose a reason for hiding this comment

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

🚫 [golangci] reported by reviewdog 🐶
marshalling is a misspelling of marshaling (misspell)


func init() {
zerolog.TimeFieldFormat = time.RFC3339
if isatty.IsTerminal(os.Stdout.Fd()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

🚫 [golangci] reported by reviewdog 🐶
if statements should only be cuddled with assignments used in the if statement itself (wsl)

@statik
Copy link
Member Author

statik commented May 17, 2021

Before and after example of log messages on terminal

Screen Shot 2021-05-16 at 22 17 51

@statik statik merged commit fecf76f into main May 17, 2021
@statik statik deleted the zerolog branch May 17, 2021 02:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant