log/slog: MarshalText and LogValue methods conflict when using slog.Info #59852
Labels
FrozenDueToAge
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I have an attribute that implements the MarshalText interface to customize its text representation. However, when I also define a LogValue method on the attribute to customize its log representation, the MarshalText method is not called anymore. This results in an incorrect output when I use slog.Info to log the attribute.
I don't know if it is correct to report this issue as a bug or not.
See https://go.dev/play/p/amo-8xYx_bh?v=gotip
Updates: #56345
What did you expect to see?
{"time":"2009-11-10T23:00:00Z","level":"INFO","msg":"sample","user":{"user_id":1,"user_name":"John Doe"}}
time=2009-11-10T23:00:00.000Z level=INFO msg=sample user="1:John Doe"
What did you see instead?
{"time":"2009-11-10T23:00:00Z","level":"INFO","msg":"sample","user":{"user_id":1,"user_name":"John Doe"}}
time=2009-11-10T23:00:00.000Z level=INFO msg=sample user.user_id=1 user.user_name="John Doe"
The text was updated successfully, but these errors were encountered: