photoprism/pkg/sev/parse.go
Michael Mayer 3c4cc40882 Security: Refactor log levels and events #98
Signed-off-by: Michael Mayer <michael@photoprism.app>
2022-10-10 16:34:07 +02:00

32 lines
629 B
Go

package sev
import (
"fmt"
"strings"
)
// Parse takes a string level and returns the severity constant.
func Parse(lvl string) (Level, error) {
switch strings.ToLower(lvl) {
case "emergency", "emerg", "panic":
return Emergency, nil
case "fatal", "alert":
return Alert, nil
case "critical", "crit":
return Critical, nil
case "error", "err":
return Error, nil
case "warn", "warning":
return Warning, nil
case "notice", "note":
return Notice, nil
case "info", "informational", "ok":
return Info, nil
case "debug":
return Debug, nil
}
var l Level
return l, fmt.Errorf("not a valid Level: %q", lvl)
}