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

38 lines
662 B
Go

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())
}