Skip to content

Commit

Permalink
add ParseLevel func to return level const
Browse files Browse the repository at this point in the history
this will allow consumers of this package to not have to do their own logic to convert known log levels to the constants defined for each one within this package.
  • Loading branch information
jamesgoodhouse authored Nov 3, 2022
1 parent 6267eb7 commit bd00e85
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,24 @@ func Level() Lvl {
return global.Level()
}

func ParseLevel(lvl string) (Lvl, error) {
switch strings.ToUpper(lvl) {
case "DEBUG":
return DEBUG, nil
case "INFO":
return INFO, nil
case "WARN":
return WARN, nil
case "ERROR":
return ERROR, nil
case "OFF":
return OFF, nil
}

var l Lvl
return l, fmt.Errorf("not a valid log level: %q", lvl)
}

func SetLevel(level Lvl) {
global.SetLevel(level)
}
Expand Down

0 comments on commit bd00e85

Please sign in to comment.