add level from string

master
bel 2020-03-15 16:40:20 +00:00
parent f55fd8f44e
commit 81ce3e5da6
1 changed files with 11 additions and 0 deletions

View File

@ -1,6 +1,7 @@
package logb
import (
"strings"
"sync"
)
@ -61,3 +62,13 @@ func (l Level) String() string {
}
return s
}
func LevelFromString(s string) Level {
s = strings.ToUpper(s)
for _, l := range []Level{ERROR, WARN, INFO, DEBUG, VERBOSE} {
if l.String() == s {
return l
}
}
return INFO
}