diff --git a/log/log.go b/log/log.go index 25f719a..954d492 100644 --- a/log/log.go +++ b/log/log.go @@ -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) }