-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Update to work with released log/slog #1320
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1320 +/- ##
==========================================
- Coverage 97.77% 97.45% -0.32%
==========================================
Files 51 52 +1
Lines 3366 3463 +97
==========================================
+ Hits 3291 3375 +84
- Misses 65 77 +12
- Partials 10 11 +1
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this change! I've left some suggestions.
Would you mind also updating the zapslog/doc.go (or creating one if it doesn't exist)
to indicate that it'll use golang.org/x/exp/slog for versions of Go before 1.21, and log/slog for versions after.
exp/go.mod
Outdated
go 1.19 | ||
go 1.21 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Increasing the minimum required Go version isn't necessary if we're using //go:build
directives to support exp/'s slog package for older versions.
exp/zapslog/slog_old.go
Outdated
@@ -0,0 +1,190 @@ | |||
//go:build go1 && !go1.21 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typically, for Go-version-specific files, we've named them foo_pre_go$version
and foo_go$version
.
For example, we have https://github.com/uber-go/zap/blob/fcfd368624a286486e62d46deba7e42c20164616/array_go118.go.
(There's no pre-Go version for that.)
So this should probably be called slog_pre_go121.go.
exp/zapslog/slog.go
Outdated
@@ -1,3 +1,5 @@ | |||
//go:build go1.21 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And this should be called slog_go121.go.
PR updated:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple comments probably out of scope for this PR,
but should be addressed before we consider upgrading this to the main Zap package.
Also, we should only add the log/slog-based version to the main Zap package.
The exp-based version should be deleted at that point.
@@ -0,0 +1,190 @@ | |||
// Copyright (c) 2023 Uber Technologies, Inc. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We probably need a slogtest to check that the handler is right.
|
||
// WithAttrs returns a new Handler whose attributes consist of | ||
// both the receiver's attributes and the arguments. | ||
func (h *Handler) WithAttrs(attrs []slog.Attr) slog.Handler { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably be covered before we consider upgrading this package to the main Zap module.
Signed-off-by: Juan C. Müller <me@juancmuller.com>
The exp package still supports Go 1.20. The std log/slog package will be used only on Go 1.21.
We place the build tag after the copyright notice.
This change makes the tests on 1.19 and 1.20 actually read these files Signed-off-by: Juan C. Müller <me@juancmuller.com>
Signed-off-by: Juan C. Müller <me@juancmuller.com>
Signed-off-by: Juan C. Müller <me@juancmuller.com>
Thanks, @abhinav. Just added a couple of commits fixing test and lint running. |
Constraints don't need the go1.19 minimum. Just "anything before 1.21" is good enough.
This is based on #1318