Skip to content

Commit 77e35e4

Browse files
author
Dean Karn
authored
add log level parser helper (#44)
1 parent e00e993 commit 77e35e4

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

level.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package log
22

33
import (
44
"bytes"
5+
"strings"
56
)
67

78
// 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 {
5455
}
5556
}
5657

57-
func level(s string) Level {
58-
switch s {
58+
// ParseLevel parses the provided strings log level or if not supported return 255
59+
func ParseLevel(s string) Level {
60+
switch strings.ToUpper(s) {
5961
case "DEBUG":
6062
return DebugLevel
6163
case "INFO":
@@ -84,6 +86,6 @@ func (l Level) MarshalJSON() ([]byte, error) {
8486

8587
// UnmarshalJSON implementation.
8688
func (l *Level) UnmarshalJSON(b []byte) error {
87-
*l = level(string(bytes.Trim(b, `"`)))
89+
*l = ParseLevel(string(bytes.Trim(b, `"`)))
8890
return nil
8991
}

0 commit comments

Comments
 (0)