Skip to content

log/slog: slog writes nil map as "map[]", not "nil" #69496

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

Closed
fedulovivan opened this issue Sep 17, 2024 · 3 comments
Closed

log/slog: slog writes nil map as "map[]", not "nil" #69496

fedulovivan opened this issue Sep 17, 2024 · 3 comments

Comments

@fedulovivan
Copy link

Go version

go version go1.22.5 darwin/arm64

Output of go env in your module/workspace:

GO111MODULE=''

What did you do?

package main
import "log/slog"
func main() {
var value map[string]string = nil
slog.Error("message", "value", value)
}

What did you see happen?

2009/11/10 23:00:00 ERROR message value=map[]

What did you expect to see?

2009/11/10 23:00:00 ERROR message value=nil

@seankhliao
Copy link
Member

fmt does the same https://go.dev/play/p/MAaylMZGDeN

@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Sep 17, 2024
@fedulovivan
Copy link
Author

Сannot understand why fmt is used as reference here. As for me it would be convenient to distinquish between empty and non-initialised maps. Current approach leads to confusion.

@seankhliao
Copy link
Member

from the docs:

Otherwise, the result of fmt.Sprint is written.

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

No branches or pull requests

2 participants