mlog: implement LevelFromString
This commit is contained in:
parent
20c6f95091
commit
15b84cb173
21
mlog/mlog.go
21
mlog/mlog.go
@ -22,6 +22,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/mediocregopher/mediocre-go-lib/merr"
|
"github.com/mediocregopher/mediocre-go-lib/merr"
|
||||||
@ -74,6 +75,26 @@ var (
|
|||||||
FatalLevel Level = level{s: "FATAL", i: 0}
|
FatalLevel Level = level{s: "FATAL", i: 0}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// LevelFromString takes a string describing one of the pre-defined Levels (e.g.
|
||||||
|
// "debug" or "INFO") and returns the corresponding Level instance, or nil if
|
||||||
|
// the string doesn't describe any of the predefined Levels.
|
||||||
|
func LevelFromString(s string) Level {
|
||||||
|
switch strings.TrimSpace(strings.ToUpper(s)) {
|
||||||
|
case "DEBUG":
|
||||||
|
return DebugLevel
|
||||||
|
case "INFO":
|
||||||
|
return InfoLevel
|
||||||
|
case "WARN":
|
||||||
|
return WarnLevel
|
||||||
|
case "ERROR":
|
||||||
|
return ErrorLevel
|
||||||
|
case "FATAL":
|
||||||
|
return FatalLevel
|
||||||
|
default:
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
// KVer is used to provide context to a log entry in the form of a dynamic set
|
// KVer is used to provide context to a log entry in the form of a dynamic set
|
||||||
|
Loading…
Reference in New Issue
Block a user