Files
kurious/internal/common/xlog/xlog.go
2023-12-09 00:33:12 +03:00

68 lines
993 B
Go

package xlog
import (
"bytes"
"errors"
)
type Level uint8
const (
LevelDebug Level = iota
LevelInfo
LevelWarn
LevelError
)
func (l *Level) UnmarshalText(data []byte) error {
switch levelstr := string(bytes.ToLower(data)); levelstr {
case "debug":
*l = LevelDebug
case "info":
*l = LevelInfo
case "warn":
*l = LevelWarn
case "error":
*l = LevelError
default:
return errors.New("unsupported level " + levelstr)
}
return nil
}
func (l Level) String() string {
switch l {
case LevelDebug:
return "debug"
case LevelInfo:
return "info"
case LevelWarn:
return "warn"
case LevelError:
return "error"
default:
return ""
}
}
type Format uint8
const (
FormatText Format = iota
FormatJSON
)
func (f *Format) UnmarshalText(data []byte) error {
switch formatstr := string(bytes.ToLower(data)); formatstr {
case "debug":
*f = FormatText
case "info":
*f = FormatJSON
default:
return errors.New("unsupported format " + formatstr)
}
return nil
}