Documentation ¶
Index ¶
- Constants
- func CtxWithAttrs(ctx context.Context, attrs ...Attr) context.Context
- func ExtendCtx(dest, ctx context.Context, attrs ...Attr) context.Context
- type Attr
- func AAny(key string, value any) Attr
- func ABool(key string, value bool) Attr
- func ADuration(key string, value time.Duration) Attr
- func AFloat64(key string, value float64) Attr
- func AGroup(key string, attrs ...Attr) Attr
- func AInt(key string, value int) Attr
- func AInt64(key string, value int64) Attr
- func AString(key string, value string) Attr
- func ATime(key string, value time.Time) Attr
- func AUint64(key string, value uint64) Attr
- type Clock
- type Discard
- type DiscardHandler
- type Handler
- type KLogger
- type Level
- type LevelLogger
- func (l *LevelLogger) Debug(ctx context.Context, msg string, attrs ...Attr)
- func (l *LevelLogger) Err(ctx context.Context, err error, attrs ...Attr)
- func (l *LevelLogger) Error(ctx context.Context, msg string, attrs ...Attr)
- func (l *LevelLogger) Info(ctx context.Context, msg string, attrs ...Attr)
- func (l *LevelLogger) Warn(ctx context.Context, msg string, attrs ...Attr)
- func (l *LevelLogger) WarnErr(ctx context.Context, err error, attrs ...Attr)
- type Logger
- type LoggerOpt
- type RealTime
- type Record
- type SlogHandler
- type SyncWriter
Constants ¶
const ( LevelDebug = slog.LevelDebug LevelInfo = slog.LevelInfo LevelWarn = slog.LevelWarn LevelError = slog.LevelError )
Variables ¶
This section is empty.
Functions ¶
func CtxWithAttrs ¶
CtxWithAttrs adds log attrs to context
Types ¶
type DiscardHandler ¶
type DiscardHandler struct{}
DiscardHandler is a Handler that discards logs
func (DiscardHandler) Enabled ¶
func (d DiscardHandler) Enabled(ctx context.Context, level Level) bool
func (DiscardHandler) Handle ¶
func (d DiscardHandler) Handle(ctx context.Context, rec Record) error
func (DiscardHandler) Subhandler ¶
func (d DiscardHandler) Subhandler(modSegment string, attrs []Attr) Handler
type Handler ¶
type Handler interface { Enabled(ctx context.Context, level Level) bool Handle(ctx context.Context, rec Record) error Subhandler(modSegment string, attrs []Attr) Handler }
Handler is a log event handler
type KLogger ¶
type KLogger struct {
// contains filtered or unexported fields
}
KLogger is a context logger that writes logs to a Handler
func (*KLogger) Enabled ¶
Enabled implements Logger and returns if the logger is enabled for a level
type LevelLogger ¶
LevelLogger provides convenience methods to log at particular levels
func NewLevelLogger ¶
func NewLevelLogger(l Logger) *LevelLogger
NewLevelLogger creates a new *LevelLogger
func (*LevelLogger) Debug ¶
func (l *LevelLogger) Debug(ctx context.Context, msg string, attrs ...Attr)
Debug logs at LevelDebug
func (*LevelLogger) Err ¶
func (l *LevelLogger) Err(ctx context.Context, err error, attrs ...Attr)
Err logs an error LevelError
func (*LevelLogger) Error ¶
func (l *LevelLogger) Error(ctx context.Context, msg string, attrs ...Attr)
Error logs at LevelError
func (*LevelLogger) Info ¶
func (l *LevelLogger) Info(ctx context.Context, msg string, attrs ...Attr)
Info logs at LevelInfo
type Logger ¶
type Logger interface { Enabled(ctx context.Context, level Level) bool Log(ctx context.Context, level Level, skip int, msg string, attrs ...Attr) Handler() Handler Sublogger(modSegment string, attrs ...Attr) Logger }
Logger writes logs with context
type LoggerOpt ¶
type LoggerOpt = func(l *KLogger)
LoggerOpt is an options function for New
func OptHandler ¶
func OptMinLevel ¶
func OptMinLevelStr ¶
OptMinLevelStr returns a LoggerOpt that sets KLogger minLevel from a string
type SlogHandler ¶
type SlogHandler struct { FieldTimeInfo string FieldCaller string FieldMod string ModSeparator string Mod string // contains filtered or unexported fields }
SlogHandler writes logs to an slog.Handler
func NewJSONSlogHandler ¶
func NewJSONSlogHandler(w io.Writer) *SlogHandler
func NewSlogHandler ¶
func NewSlogHandler(handler slog.Handler) *SlogHandler
NewSlogHandler creates a new *SlogHandler
func NewTextSlogHandler ¶
func NewTextSlogHandler(w io.Writer) *SlogHandler
func (*SlogHandler) Subhandler ¶
func (h *SlogHandler) Subhandler(modSegment string, attrs []Attr) Handler
type SyncWriter ¶
type SyncWriter struct {
// contains filtered or unexported fields
}
SyncWriter is a thread safe writer
func NewSyncWriter ¶
func NewSyncWriter(w io.Writer) *SyncWriter
NewSyncWriter creates a new *SyncWriter