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

log/slog: handler.Enabled should be called with context.Background() instead of nil ctx #61457

Closed
powerman opened this issue Jul 19, 2023 · 1 comment

Comments

@powerman
Copy link

What version of Go are you using (go version)?

$ go version
go version go1.21rc2 linux/amd64

Does this issue reproduce with the latest release?

Yes.

What did you do?

Look at the source code: https://cs.opensource.google/go/go/+/refs/tags/go1.21rc2:src/log/slog/logger.go;l=209-210

What did you expect to see?

This if must be executed before calling l.Enabled(ctx): https://cs.opensource.google/go/go/+/refs/tags/go1.21rc2:src/log/slog/logger.go;l=222-224

What did you see instead?

Current implementation violates current doc. https://pkg.go.dev/log/slog#Handler says:

	// If called from a Logger method, the first argument is the context
	// passed to that method, or context.Background() if nil was passed
	// or the method does not take a context.
...
	Enabled(context.Context, Level) bool
@powerman
Copy link
Author

Oops, sorry, looks like this is already implemented in l.Enabled().

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

1 participant