restore v0.3.0

This commit is contained in:
andrey1s
2021-09-19 17:25:47 +03:00
parent f9ae79614a
commit deb67b0008
37 changed files with 3472 additions and 332 deletions

73
level/level.go Normal file
View File

@@ -0,0 +1,73 @@
package level
import (
"encoding/json"
"strings"
)
//go:generate stringer -type=Level -linecomment
var (
_ json.Marshaler = Level(0)
_ json.Unmarshaler = (*Level)(nil)
)
// Level log.
type Level uint32
// available log levels.
const (
Emergency Level = iota // emergency
Alert // alert
Critical // critical
Error // error
Warning // warning
Notice // notice
Info // info
Debug // debug
)
func (l Level) MarshalJSON() ([]byte, error) {
return json.Marshal(l.String())
}
func (l Level) Is(level Level) bool {
return level == l
}
func (l Level) Enabled(level Level) bool {
return l <= level
}
func (l *Level) UnmarshalJSON(in []byte) error {
var v string
if err := json.Unmarshal(in, &v); err != nil {
return err
}
lvl := Parse(v)
*l = lvl
return nil
}
func Parse(lvl string) Level {
switch strings.ToLower(lvl) {
case "debug", "Debug", "DEBUG":
return Debug
case "info", "Info", "INFO":
return Info
case "notice", "Notice", "NOTICE":
return Notice
case "warning", "Warning", "WARNING":
return Warning
case "error", "Error", "ERROR":
return Error
case "critical", "Critical", "CRITICAL":
return Critical
case "alert", "Alert", "ALERT":
return Alert
default:
return Emergency
}
}

30
level/level_string.go Normal file
View File

@@ -0,0 +1,30 @@
// Code generated by "stringer -type=Level -linecomment"; DO NOT EDIT.
package level
import "strconv"
func _() {
// An "invalid array index" compiler error signifies that the constant values have changed.
// Re-run the stringer command to generate them again.
var x [1]struct{}
_ = x[Emergency-0]
_ = x[Alert-1]
_ = x[Critical-2]
_ = x[Error-3]
_ = x[Warning-4]
_ = x[Notice-5]
_ = x[Info-6]
_ = x[Debug-7]
}
const _Level_name = "emergencyalertcriticalerrorwarningnoticeinfodebug"
var _Level_index = [...]uint8{0, 9, 14, 22, 27, 34, 40, 44, 49}
func (i Level) String() string {
if i >= Level(len(_Level_index)-1) {
return "Level(" + strconv.FormatInt(int64(i), 10) + ")"
}
return _Level_name[_Level_index[i]:_Level_index[i+1]]
}