-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
✨ Add helpers for remaining Zap options #639
✨ Add helpers for remaining Zap options #639
Conversation
Hi @hasbro17. Thanks for your PR. I'm waiting for a kubernetes-sigs or kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
This covers the all the provided options but I was wondering if we should expose more predefined options for the EncoderConfig? import (
"os"
uzap "go.uber.org/zap"
"go.uber.org/zap/zapcore"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
logf "sigs.k8s.io/controller-runtime/pkg/runtime/log"
)
var log = logf.Log.WithName("cmd")
func main() {
ecfg := uzap.NewDevelopmentEncoderConfig()
ecfg.EncodeTime = zapcore.EpochTimeEncoder
ecfg.EncodeLevel = zapcore.LowercaseLevelEncoder
encoder := zapcore.NewConsoleEncoder(ecfg)
zapLogr := zap.New(zap.Development(true), zap.DestWritter(os.Stdout), zap.Encoder(encoder))
logf.SetLogger(zapLogr)
log.Info("Test message", "value", 1)
} And having options for both Encoder and EncoderConfig might be confusing if you could set two different configs via both options. |
@alvaroaleman I also just realized that the destination writer option is named controller-runtime/pkg/log/zap/zap.go Line 97 in 16c93b0
Is that supposed to be with a single T |
/ok-to-test
Yes, seems there is a typo. Please change it, I guess Solly will defer changing that to a new release anyways. |
pkg/log/zap/zap.go
Outdated
} | ||
} | ||
|
||
// Encoder sets the Encoder option for the logger |
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.
Should we probably mention the defaults in the godocs for the new funcs?
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 have them defined already for the Option fields so I wasn't sure if I should repeat those here again.
controller-runtime/pkg/log/zap/zap.go
Lines 93 to 94 in 16c93b0
// The encoder to use, defaults to console when Development is true | |
// and JSON otherwise |
pkg/log/zap/zap.go
Outdated
} | ||
|
||
// ZapOpts appends zapOpts to the raw zap.Options option of the logger | ||
func ZapOpts(zapOpts []zap.Option) func(o *Options) { |
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.
Maybe RawZapOpts
to avoid the linter error?
ea7e394
to
385befd
Compare
Didn't see #646 get merged which has the first two options. I'll rebase this to only add the remaining option helpers. |
385befd
to
da3f070
Compare
da3f070
to
172860e
Compare
pkg/log/zap/zap.go
Outdated
@@ -82,18 +77,51 @@ type Opts func(*Options) | |||
// See Options.Development | |||
func UseDevMode(enabled bool) Opts { | |||
return func(o *Options) { | |||
o.Development = true | |||
o.Development = enabled |
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.
@DirectXMan12 Did you mean to fix this?
#646 (comment)
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.
/lgtm |
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.
minor nit, otherwise fine
pkg/log/zap/zap.go
Outdated
|
||
// RawZapOpts allows appending arbitrary zap.Options to configure the underlying zap logger. | ||
// See Options.RawZapOpts | ||
func RawZapOpts(zapOpts []zap.Option) func(o *Options) { |
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.
nit: make this variadic
172860e
to
3fba417
Compare
New changes are detected. LGTM label has been removed. |
[APPROVALNOTIFIER] This PR is APPROVED Approval requirements bypassed by manually added approval. This pull-request has been approved by: hasbro17 The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
/lgtm |
This PR adds predefined functional options for more easily setting the logger options in
pkg/log/zap
.Follow up to #560 per #560 (comment)
/cc @DirectXMan12 @alvaroaleman