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

Update to work with released log/slog #1320

Merged
merged 10 commits into from
Aug 19, 2023
Merged

Update to work with released log/slog #1320

merged 10 commits into from
Aug 19, 2023

Conversation

jcmuller
Copy link
Contributor

@jcmuller jcmuller commented Aug 14, 2023

This is based on #1318

@CLAassistant
Copy link

CLAassistant commented Aug 14, 2023

CLA assistant check
All committers have signed the CLA.

@codecov
Copy link

codecov bot commented Aug 15, 2023

Codecov Report

Merging #1320 (4d5fbfb) into master (d2aeb27) will decrease coverage by 0.32%.
The diff coverage is 86.59%.

@@            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     
Files Changed Coverage Δ
exp/zapslog/slog_pre_go121.go 86.59% <ø> (ø)
exp/zapslog/slog_go121.go 86.59% <86.59%> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Copy link
Collaborator

@abhinav abhinav left a 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
Copy link
Collaborator

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.

@@ -0,0 +1,190 @@
//go:build go1 && !go1.21
Copy link
Collaborator

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.

@@ -1,3 +1,5 @@
//go:build go1.21
Copy link
Collaborator

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.

@abhinav
Copy link
Collaborator

abhinav commented Aug 16, 2023

PR updated:

  • Merged master in so tests run against 1.20 and 1.21
  • Made the renames I suggested above
  • Lowered the go directive to Go 1.20
  • Updated doc.go as suggested above

Copy link
Collaborator

@abhinav abhinav left a 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.
Copy link
Collaborator

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.

https://pkg.go.dev/testing/slogtest#TestHandler


// 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 {
Copy link
Collaborator

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.

shreyner and others added 8 commits August 17, 2023 09:11
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>
@jcmuller
Copy link
Contributor Author

jcmuller commented Aug 17, 2023

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.
@abhinav
Copy link
Collaborator

abhinav commented Aug 19, 2023

@sywhang @mway please merge when you have a chance. I can't do anything about the coverage error. I expect we should fix that when we move this to the non-exp Zap module.

@mway
Copy link
Member

mway commented Aug 19, 2023

@sywhang @mway please merge when you have a chance. I can't do anything about the coverage error. I expect we should fix that when we move this to the non-exp Zap module.

Ack, no worries.

@mway mway merged commit b454e18 into uber-go:master Aug 19, 2023
5 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

6 participants