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

✨ Allow fine-grained configuration of log/zap #560

Merged
merged 1 commit into from
Aug 26, 2019

Conversation

alvaroaleman
Copy link
Member

This PR changes the logger in pkg/log/zap to additionally allow configuring the Encoder and the LogLevel. This is done using the functional style opts pattern.

Backwards-compatibility is kept by keeping the existing public interface and extending it with a New to get a logr.Logger and a NewRaw to get a *zap.Logger.

Fixes #442
Closes #467

/assign @DirectXMan12

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Aug 10, 2019
@k8s-ci-robot k8s-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Aug 10, 2019
Copy link
Contributor

@DirectXMan12 DirectXMan12 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we have options for the comment settings?

@@ -29,6 +29,11 @@ import (
"go.uber.org/zap/zapcore"
)

// New returns a brand new Logger configured with Opts
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please note that this (and NewRaw) use KubeAwareEncoder

@DirectXMan12
Copy link
Contributor

also need a comment explaining why we have LoggerTo and New, and what the differences are.

@alvaroaleman
Copy link
Member Author

Should we have options for the comment settings?

What do you mean by "comment settings"?

also need a comment explaining why we have LoggerTo and New, and what the differences are.

The reason I left those is just compatibility, other than that I do not see a good reason for them to exist. Do you know one? Else I would just add that as a comment.

@DirectXMan12
Copy link
Contributor

lol, sorry, "common settings" :-P.

Compatibility is the big reason for the others existing. You could also just add

// <comment>
//
// Deprecated: Use New(Development) instead

or similar

@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Aug 19, 2019
@alvaroaleman
Copy link
Member Author

@DirectXMan12 I've updated and expanded the godocs and also added the possibility to configure the log level for stracktraces. The only common thing left now that can not be configured is enablement of the KubeAwareDecoder, reasoning was that this project is very much intended to be used in conjunction with Kubernetes APIs so there is no good reason to not want that or WDYT?

@DirectXMan12
Copy link
Contributor

Seems reasonable to just always enable it

@alvaroaleman
Copy link
Member Author

I think this is good to go, ptal

//
// Deprecated, use New() and the functional opts pattern instead:
//
// New(func(o *Options){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we'll want to follow up (can do it in a follow-up PR) with some predefined options for this, instead of making people write this themselves.

@DirectXMan12
Copy link
Contributor

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Aug 26, 2019
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: alvaroaleman, DirectXMan12

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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 26, 2019
@k8s-ci-robot k8s-ci-robot merged commit d90bbc6 into kubernetes-sigs:master Aug 26, 2019
DirectXMan12 pushed a commit that referenced this pull request Jan 31, 2020
📖 add kubebuilder workshop in the book
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

log/zap: Allow configuring formatter independently of debug option
3 participants