Documentation
¶
Index ¶
- func Debug(msg string, attrs ...Attr)
- func DebugContext(ctx context.Context, msg string, attrs ...Attr)
- func Debugf(format string, args ...any)
- func Error(msg string, attrs ...Attr)
- func ErrorContext(ctx context.Context, msg string, attrs ...Attr)
- func Errorf(format string, args ...any)
- func Info(msg string, attrs ...Attr)
- func InfoContext(ctx context.Context, msg string, attrs ...Attr)
- func Infof(format string, args ...any)
- func InitWithBackends(backends ...Backend)
- func Sync() error
- func Warn(msg string, attrs ...Attr)
- func WarnContext(ctx context.Context, msg string, attrs ...Attr)
- func Warnf(format string, args ...any)
- type AddCallerStatus
- type Attr
- func Any(key string, value any) Attr
- func Bool(key string, value bool) Attr
- func Duration(key string, value time.Duration) Attr
- func Err(err error) Attr
- func Float64(key string, value float64) Attr
- func Group(key string, attrs ...Attr) Attr
- func Int(key string, value int) Attr
- func Int64(key string, value int64) Attr
- func MergeAttrs(base []Attr, explicit []Attr) []Attr
- func String(key, value string) Attr
- func Time(key string, value time.Time) Attr
- func Uint64(key string, value uint64) Attr
- type Backend
- type BaseLogger
- type ContextAttrExtractor
- type ContextLogger
- type ContextMapExtractor
- type Field
- type FormatLogger
- type Level
- type Logger
- type MultiBackend
- type Option
- type Options
- type StdioBackend
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DebugContext ¶ added in v0.0.3
func ErrorContext ¶ added in v0.0.3
func InitWithBackends ¶ added in v0.0.3
func InitWithBackends(backends ...Backend)
InitWithBackends initializes global logger with custom backend(s).
Types ¶
type AddCallerStatus ¶
type AddCallerStatus int
AddCallerStatus represents the state of caller information in log entries.
const ( // AddCallerStatusKeep maintains the current caller setting without changes. AddCallerStatusKeep AddCallerStatus = iota // AddCallerStatusEnable adds caller information to log entries. AddCallerStatusEnable // AddCallerStatusDisable removes caller information from log entries. AddCallerStatusDisable )
type Attr ¶ added in v0.0.3
Attr is a strongly-typed structured log field based on slog's value model.
func MergeAttrs ¶ added in v0.0.3
MergeAttrs merges base attrs with explicit attrs. Explicit attrs override same-key values from base.
type Backend ¶ added in v0.0.3
type Backend interface {
Log(ctx context.Context, level Level, msg string, attrs ...Attr)
Sync() error
With(options ...Option) Backend
}
Backend is the pluggable logging backend interface.
func NewMultiBackend ¶ added in v0.0.3
NewMultiBackend creates a backend that writes to all provided backends.
func NewNopBackend ¶ added in v0.0.3
func NewNopBackend() Backend
func WrapBackendWithContextMapMerge ¶ added in v0.0.3
func WrapBackendWithContextMapMerge(backend Backend, extractor ContextMapExtractor) Backend
WrapBackendWithContextMapMerge returns a backend wrapper using a map-based context extractor.
func WrapBackendWithContextMerge ¶ added in v0.0.3
func WrapBackendWithContextMerge(backend Backend, extractor ContextAttrExtractor) Backend
WrapBackendWithContextMerge returns a backend that merges attrs extracted from context.
type BaseLogger ¶
type BaseLogger interface {
Debug(msg string, attrs ...Attr)
Info(msg string, attrs ...Attr)
Warn(msg string, attrs ...Attr)
Error(msg string, attrs ...Attr)
}
BaseLogger defines structured logging methods.
type ContextAttrExtractor ¶ added in v0.0.3
ContextAttrExtractor extracts attributes from context for context-aware logging.
func MapContextAttrExtractor ¶ added in v0.0.3
func MapContextAttrExtractor(extractor ContextMapExtractor) ContextAttrExtractor
MapContextAttrExtractor adapts map extractors into attr extractors.
type ContextLogger ¶ added in v0.0.3
type ContextLogger interface {
DebugContext(ctx context.Context, msg string, attrs ...Attr)
InfoContext(ctx context.Context, msg string, attrs ...Attr)
WarnContext(ctx context.Context, msg string, attrs ...Attr)
ErrorContext(ctx context.Context, msg string, attrs ...Attr)
}
ContextLogger defines context-aware structured logging methods.
type ContextMapExtractor ¶ added in v0.0.3
ContextMapExtractor extracts key-value pairs from context for logging.
type FormatLogger ¶ added in v0.0.3
type FormatLogger interface {
Debugf(format string, args ...any)
Infof(format string, args ...any)
Warnf(format string, args ...any)
Errorf(format string, args ...any)
}
FormatLogger defines printf-style logging methods.
type Logger ¶
type Logger interface {
BaseLogger
ContextLogger
FormatLogger
Backend() Backend
With(options ...Option) Logger
Sync() error
}
Logger combines quick-use APIs with type-safe attrs and context support.
type MultiBackend ¶ added in v0.0.3
type MultiBackend struct {
// contains filtered or unexported fields
}
MultiBackend fan-outs each log entry to all configured backends.
func (*MultiBackend) Backends ¶ added in v0.0.3
func (m *MultiBackend) Backends() []Backend
Backends returns a snapshot of child backends.
func (*MultiBackend) Sync ¶ added in v0.0.3
func (m *MultiBackend) Sync() error
func (*MultiBackend) With ¶ added in v0.0.3
func (m *MultiBackend) With(options ...Option) Backend
type Option ¶
type Option = func(*Options)
Option is a function type for configuring logger options.
func AddCaller ¶
func AddCaller() Option
AddCaller enables caller information in log entries. This includes file names and line numbers where the log call was made.
func DisableCaller ¶
func DisableCaller() Option
DisableCaller removes caller information from log entries. This can improve performance when caller information is not needed.
func WithAttrs ¶
WithAttrs adds structured attributes to all log messages from this logger. These attributes provide consistent context across all log entries.
func WithName ¶
WithName sets the logger name for identification purposes. The name appears in log output to help distinguish between different loggers.
func WithStackAt ¶
WithStackAt enables stack trace logging at the specified level and above. Stack traces help debug issues by showing the full call chain.
type Options ¶ added in v0.0.3
type Options struct {
Name string
AddCaller AddCallerStatus
AddStackAt *Level
Attrs map[string]any
}
Options is the materialized option set consumed by backend adapters.
func NewOptions ¶ added in v0.0.3
NewOptions materializes options so backend adapters can consume them.
type StdioBackend ¶ added in v0.0.3
type StdioBackend struct {
// contains filtered or unexported fields
}
func NewStdioBackend ¶ added in v0.0.3
func NewStdioBackend(options ...Option) *StdioBackend
func (*StdioBackend) Sync ¶ added in v0.0.3
func (b *StdioBackend) Sync() error
func (*StdioBackend) With ¶ added in v0.0.3
func (b *StdioBackend) With(options ...Option) Backend