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

fix: correct field filtering logic in writeFields #680

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

yqaty
Copy link

@yqaty yqaty commented Jul 4, 2024

ConsoleWriter.Write processes custom fields specified in PartsOrder to output only their values instead of the key-value pairs. In practice:

package main

import (
	"github.com/rs/zerolog"
)

func main() {
	cw := zerolog.NewConsoleWriter()
	cw.PartsOrder = append(cw.PartsOrder, "k1")
	logger := zerolog.New(cw).With().Timestamp().Logger()
	logger.Info().Str("k1", "v1").Msg("hello world")
}

Actual output:

5:09PM INF hello world v1 k1=v1

The field k1 is duplicated, and the expected output is:

5:09PM INF hello world v1

This is due to a bug in ConsoleWrite.writeFields where it filters fields based on the default PartsOrder rather than the current PartsOrder.

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

Successfully merging this pull request may close these issues.

2 participants