Skip to content

Commit

Permalink
add log level parser helper (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dean Karn authored Jun 2, 2022
1 parent e00e993 commit 77e35e4
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions level.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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":
Expand Down Expand Up @@ -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
}

0 comments on commit 77e35e4

Please sign in to comment.