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

zapcore: Add ParseLevel #1047

Merged
merged 5 commits into from Jan 13, 2022
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 15 additions & 0 deletions zapcore/level.go
Expand Up @@ -55,6 +55,21 @@ const (
_maxLevel = FatalLevel
)

// UnmarshalLevel unmarshals a level based on the lower-case or all-caps ASCII
// representation of the log level. If the provided ASCII representation is
// invalid an error is returned.
//
// This is particularly useful when dealing with text input to configure log
// levels.
func UnmarshalLevel(text string) (Level, error) {
abhinav marked this conversation as resolved.
Show resolved Hide resolved
level := DebugLevel
abhinav marked this conversation as resolved.
Show resolved Hide resolved
err := level.UnmarshalText([]byte(text))
if err != nil {
return level, err
}
return level, nil
abhinav marked this conversation as resolved.
Show resolved Hide resolved
}

// String returns a lower-case ASCII representation of the log level.
func (l Level) String() string {
switch l {
Expand Down