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 specifying user defined log level names #1277

Open
pmalek opened this issue Apr 26, 2023 · 4 comments
Open

Allow specifying user defined log level names #1277

pmalek opened this issue Apr 26, 2023 · 4 comments

Comments

@pmalek
Copy link

pmalek commented Apr 26, 2023

Is your feature request related to a problem? Please describe.

As a user of zap I'd like to define my own custom log level, let's call it TraceLevel. It's destined to be more verbose than Debug.

Because currently the log levels are checked against a known, concrete set of values

zap/zapcore/level.go

Lines 134 to 156 in 4451b47

// CapitalString returns an all-caps ASCII representation of the log level.
func (l Level) CapitalString() string {
// Printing levels in all-caps is common enough that we should export this
// functionality.
switch l {
case DebugLevel:
return "DEBUG"
case InfoLevel:
return "INFO"
case WarnLevel:
return "WARN"
case ErrorLevel:
return "ERROR"
case DPanicLevel:
return "DPANIC"
case PanicLevel:
return "PANIC"
case FatalLevel:
return "FATAL"
default:
return fmt.Sprintf("LEVEL(%d)", l)
}
}
when pretty printing the log level name I cannot define a name on my level and see it in the logs.

All I can get is fmt.Sprintf("LEVEL(%d)", l)

Describe the solution you'd like

Define an interface that user defined log levels can be checked against and if they implement it then use it to get the name of the log level.

If that fails then resort to fmt.Sprintf("LEVEL(%d)", l).

Describe alternatives you've considered

None exist to the best of my knowledge.

Is this a breaking change?

No.

@JacobOaks
Copy link
Contributor

Internal Ref: GO-2011

@SoulPancake
Copy link

Can I work on this ? @JacobOaks

@JacobOaks
Copy link
Contributor

Can I work on this ? @JacobOaks

Of course! Feel free to open a PR.

@sywhang
Copy link
Contributor

sywhang commented May 15, 2023

Sorry I hopped late onto this thread, but I believe we shouldn't add this feature to Zap.

Allowing definitions of custom levels is a breaking change and we do not want that. See the discussions in #680.

Existing encoders and samplers could break due to such things. For example: #713 is an example of someone defining their own custom log level which broke the sampler.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

5 participants