Files
eway/internal/config/log.go
2024-01-25 16:42:08 +03:00

56 lines
898 B
Go

package config
import (
"strings"
"git.loyso.art/frx/eway/internal/entity"
)
type LogLevel uint8
const (
LogLevelDebug LogLevel = iota
LogLevelInfo
LogLevelWarn
)
func (l *LogLevel) UnmarshalText(data []byte) (err error) {
switch strings.ToLower(string(data)) {
case "debug":
*l = LogLevelDebug
case "info":
*l = LogLevelInfo
case "warn":
*l = LogLevelWarn
default:
return entity.SimpleError("unsupported level " + string(data))
}
return nil
}
type LogFormat uint8
const (
LogFormatText LogFormat = iota
LogFormatJSON
)
func (l *LogFormat) UnmarshalText(data []byte) (err error) {
switch strings.ToLower(string(data)) {
case "text":
*l = LogFormatText
case "info":
*l = LogFormatJSON
default:
return entity.SimpleError("unsupported format " + string(data))
}
return nil
}
type Log struct {
Level string `json:"level"`
Format string `json:"format"`
}