setup parser
This commit is contained in:
37
internal/common/xlog/slog.go
Normal file
37
internal/common/xlog/slog.go
Normal file
@ -0,0 +1,37 @@
|
||||
package xlog
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log/slog"
|
||||
)
|
||||
|
||||
func LevelAsSLogLevel(level Level) slog.Level {
|
||||
switch level {
|
||||
case LevelDebug:
|
||||
return slog.LevelDebug
|
||||
case LevelInfo:
|
||||
return slog.LevelInfo
|
||||
case LevelWarn:
|
||||
return slog.LevelWarn
|
||||
case LevelError:
|
||||
return slog.LevelError
|
||||
default:
|
||||
panic("unsupported level " + level.String())
|
||||
}
|
||||
}
|
||||
|
||||
func StringerAttr(name string, value fmt.Stringer) slog.Attr {
|
||||
return slog.Any(name, StringerValue(value))
|
||||
}
|
||||
|
||||
func StringerValue(s fmt.Stringer) slog.LogValuer {
|
||||
return stringerValue{s}
|
||||
}
|
||||
|
||||
type stringerValue struct {
|
||||
fmt.Stringer
|
||||
}
|
||||
|
||||
func (s stringerValue) LogValue() slog.Value {
|
||||
return slog.StringValue(s.String())
|
||||
}
|
||||
Reference in New Issue
Block a user