update level #7

Merged
andrey merged 2 commits from level into master 2024-01-01 17:00:38 +03:00
Showing only changes of commit 516731f925 - Show all commits

View File

@@ -1,6 +1,7 @@
package level
import (
"encoding"
"encoding/json"
"strings"
)
@@ -8,8 +9,12 @@ import (
//go:generate stringer -type=Level -linecomment
var (
_ json.Marshaler = Level(0)
_ json.Unmarshaler = (*Level)(nil)
_ json.Marshaler = Level(0)
_ json.Unmarshaler = (*Level)(nil)
_ encoding.TextMarshaler = Level(0)
_ encoding.TextUnmarshaler = (*Level)(nil)
_ encoding.BinaryMarshaler = Level(0)
_ encoding.BinaryUnmarshaler = (*Level)(nil)
)
// Level log.
@@ -57,6 +62,17 @@ func (l *Level) UnmarshalText(in []byte) error {
return nil
}
func (l Level) MarshalBinary() ([]byte, error) {
return []byte(l.String()), nil
}
func (l *Level) UnmarshalBinary(in []byte) error {
lvl := Parse(string(in))
*l = lvl
return nil
}
func Parse(lvl string) Level {
switch strings.ToLower(lvl) {
case "debug", "Debug", "DEBUG":