Skip to content

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