From 77e35e47a72c0afd8a70f1d41cf6f5d2a89252dc Mon Sep 17 00:00:00 2001 From: Dean Karn Date: Thu, 2 Jun 2022 16:25:09 -0700 Subject: [PATCH] add log level parser helper (#44) --- level.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/level.go b/level.go index af60027..55c193d 100644 --- a/level.go +++ b/level.go @@ -2,6 +2,7 @@ package log import ( "bytes" + "strings" ) // AllLevels is an array of all log levels, for easier registering of all levels to a handler @@ -54,8 +55,9 @@ func (l Level) String() string { } } -func level(s string) Level { - switch s { +// ParseLevel parses the provided strings log level or if not supported return 255 +func ParseLevel(s string) Level { + switch strings.ToUpper(s) { case "DEBUG": return DebugLevel case "INFO": @@ -84,6 +86,6 @@ func (l Level) MarshalJSON() ([]byte, error) { // UnmarshalJSON implementation. func (l *Level) UnmarshalJSON(b []byte) error { - *l = level(string(bytes.Trim(b, `"`))) + *l = ParseLevel(string(bytes.Trim(b, `"`))) return nil }