add ParseLevel to get Level from string

This commit is contained in:
Joel Scoble
2014-09-17 17:03:34 -05:00
parent 89b6d460f0
commit 4e6e671281
2 changed files with 59 additions and 0 deletions
+22
View File
@@ -1,6 +1,7 @@
package logrus
import (
"fmt"
"log"
)
@@ -30,6 +31,27 @@ func (level Level) String() string {
return "unknown"
}
func ParseLevel(lvl string) (Level, error) {
switch lvl {
case "panic":
return PanicLevel, nil
case "fatal":
return FatalLevel, nil
case "error":
return ErrorLevel, nil
case "warn", "warning":
return WarnLevel, nil
case "info":
return InfoLevel, nil
case "debug", "dbg":
return DebugLevel, nil
}
var l Level
return l, fmt.Errorf("not a valid logrus Level: %q", lvl)
}
// These are the different logging levels. You can set the logging level to log
// on your instance of logger, obtained with `logrus.New()`.
const (