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

Expand LevelEnabler interface by method Level() Level #1143

Closed

Conversation

krupyansky
Copy link

No description provided.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

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 the contribution, @krupyansky, but adding a new method to an existing interface is a breaking change. We're not currently entertaining breaking changes to Zap.

If you share what problem you're trying to solve with this, we can work with you to try to find a solution to your problem.

@krupyansky
Copy link
Author

krupyansky commented Aug 4, 2022

Thanks for the contribution, @krupyansky, but adding a new method to an existing interface is a breaking change. We're not currently entertaining breaking changes to Zap.

If you share what problem you're trying to solve with this, we can work with you to try to find a solution to your problem.

I need an external package to be able to get the logging level from zap logger that I initialize in an internal package.
It is not possible to directly pass the logging level to an external package.

For logrus, this problem is solved in the following way:
https://pkg.go.dev/github.com/sirupsen/logrus#Logger.GetLevel
https://pkg.go.dev/github.com/sirupsen/logrus#Entry

I need a similar feature from zap logger.

abhinav added a commit that referenced this pull request Aug 15, 2022
Add a new function LevelOf that reports the minimum enabled log level
for a LevelEnabler.

This works by looping through all known Zap levels in-order,
returning the newly introduced UnknownLevel if none of the known levels
are enabled.

A LevelEnabler or Core implementation may implement the `Level() Level`
method to override and optimize this behavior.
AtomicLevel already implemented this method.
This change adds the method to all Core implementations shipped with
Zap.

Note:
UnknownLevel is set at FatalLevel+1 to account for the possibility that
users of Zap are using DebugLevel-1 as their own custom log level--even
though this isn't supported, it's preferable not to break these users.
Users are less likely to use FatalLevel+1 since Fatal means "exit the
application."

Resolves #1144
Supersedes #1143, which was not backwards compatible
@abhinav
Copy link
Collaborator

abhinav commented Aug 16, 2022

Superseded by #1147.
Thanks for the initial contribution and opening the discussion around it, @krupyansky!

@abhinav abhinav closed this Aug 16, 2022
@krupyansky krupyansky deleted the add_level_to_level_enabler_i branch August 16, 2022 12:49
@krupyansky
Copy link
Author

Thank you for your response and feedback, @abhinav!

abhinav added a commit that referenced this pull request Aug 16, 2022
Add a new function LevelOf that reports the minimum enabled log level
for a LevelEnabler.
This works by looping through all known Zap levels in-order,
returning the newly introduced UnknownLevel if none of the known levels
are enabled.
A LevelEnabler or Core implementation may implement the Level() Level
method to override and optimize this behavior.
AtomicLevel already implemented this method.
This change adds the method to all Core implementations shipped with
Zap.
Note:
UnknownLevel is set at FatalLevel+1 to account for the possibility that
users of Zap are using DebugLevel-1 as their own custom log level--even
though this isn't supported, it's preferable not to break these users.
Users are less likely to use FatalLevel+1 since Fatal means "exit the
application."
Refs #1144
Supersedes #1143, which was not backwards compatible
Refs GO-1586
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.

3 participants