Skip to content

Commit bd00e85

Browse files
add ParseLevel func to return level const
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.
1 parent 6267eb7 commit bd00e85

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

log/log.go

+18
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,24 @@ func Level() Lvl {
248248
return global.Level()
249249
}
250250

251+
func ParseLevel(lvl string) (Lvl, error) {
252+
switch strings.ToUpper(lvl) {
253+
case "DEBUG":
254+
return DEBUG, nil
255+
case "INFO":
256+
return INFO, nil
257+
case "WARN":
258+
return WARN, nil
259+
case "ERROR":
260+
return ERROR, nil
261+
case "OFF":
262+
return OFF, nil
263+
}
264+
265+
var l Lvl
266+
return l, fmt.Errorf("not a valid log level: %q", lvl)
267+
}
268+
251269
func SetLevel(level Lvl) {
252270
global.SetLevel(level)
253271
}

0 commit comments

Comments
 (0)