Make logrus.Level implement encoding.TextUnmarshaler

This commit is contained in:
Shun Yanaura
2018-10-19 20:35:56 +09:00
parent 680f584d62
commit 5c1f2cd52c
2 changed files with 25 additions and 0 deletions
+12
View File
@@ -53,6 +53,18 @@ func ParseLevel(lvl string) (Level, error) {
return l, fmt.Errorf("not a valid logrus Level: %q", lvl)
}
// UnmarshalText implements encoding.TextUnmarshaler.
func (level *Level) UnmarshalText(text []byte) error {
l, err := ParseLevel(string(text))
if err != nil {
return err
}
*level = Level(l)
return nil
}
// A constant exposing all logging levels
var AllLevels = []Level{
PanicLevel,