Documentation
¶
Overview ¶
Package log provides structured runtime logging with context enrichment, configurable severity thresholds, and pluggable output backends.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RegisterContextEnricher ¶
func RegisterContextEnricher(fn ContextEnricher)
RegisterContextEnricher sets the global context enricher used by all loggers. Typically called from an init() in the package that owns PluginContext.
func SetDefault ¶
func SetDefault(l Logger)
SetDefault atomically replaces the process-wide logger; nil resets it to NewNop.
Types ¶
type Backend ¶
type Backend interface {
Write(ctx context.Context, record Record) error
Sync(ctx context.Context) error
}
Backend emits log records to a concrete logging implementation.
type Config ¶
type Config struct {
Name string
Fields []Field
Backend Backend
Level *LevelController
Now func() time.Time
}
Config selects the logger's name, persistent fields, output, threshold, and clock.
type ContextEnricher ¶
ContextEnricher extracts structured fields from a context. Registered via RegisterContextEnricher to break import cycles.
type Field ¶
Field is a structured key/value pair attached to log records.
type HCLBackend ¶
type HCLBackend struct {
// contains filtered or unexported fields
}
HCLBackend emits records to an hclog logger.
func NewDefaultHCLBackend ¶
func NewDefaultHCLBackend(name string, level Level) *HCLBackend
NewDefaultHCLBackend creates an hclog backend with its default output options.
func NewHCLBackend ¶
func NewHCLBackend(logger hclog.Logger) *HCLBackend
NewHCLBackend wraps logger, using a null logger when logger is nil.
func (*HCLBackend) Named ¶
func (b *HCLBackend) Named(name string) *HCLBackend
Named returns a backend with a child logger, or this backend for an empty name.
func (*HCLBackend) SetLevel ¶
func (b *HCLBackend) SetLevel(level Level)
SetLevel updates the underlying hclog severity threshold.
type Level ¶
type Level int32
Level is the logging severity level.
const ( // LevelTrace enables the most detailed diagnostic records. LevelTrace Level = iota // LevelDebug enables debugging records and more severe records. LevelDebug // LevelInfo enables informational records and more severe records. LevelInfo // LevelWarn enables warning records and more severe records. LevelWarn // LevelError enables error and fatal records. LevelError // LevelFatal marks fatal conditions without requiring process termination. LevelFatal )
func ParseLevel ¶
ParseLevel accepts case-insensitive severity names and surrounding whitespace. Empty input selects info; "warning" aliases warn. Invalid input returns info and an error.
type LevelController ¶
type LevelController struct {
// contains filtered or unexported fields
}
LevelController manages the effective log level at runtime.
func NewLevelController ¶
func NewLevelController(initial Level) *LevelController
NewLevelController creates a concurrency-safe threshold controller.
func (*LevelController) Enabled ¶
func (c *LevelController) Enabled(level Level) bool
Enabled reports whether level meets the current severity threshold.
func (*LevelController) Level ¶
func (c *LevelController) Level() Level
Level returns the current severity threshold.
func (*LevelController) Set ¶
func (c *LevelController) Set(level Level)
Set atomically replaces the severity threshold.
type Logger ¶
type Logger interface {
Named(name string) Logger
With(fields ...Field) Logger
Enabled(ctx context.Context, level Level) bool
Log(ctx context.Context, level Level, msg string, fields ...Field)
Trace(ctx context.Context, msg string, fields ...Field)
Debug(ctx context.Context, msg string, fields ...Field)
Info(ctx context.Context, msg string, fields ...Field)
Warn(ctx context.Context, msg string, fields ...Field)
Error(ctx context.Context, msg string, fields ...Field)
Fatal(ctx context.Context, msg string, fields ...Field)
Tracew(ctx context.Context, msg string, kv ...any)
Debugw(ctx context.Context, msg string, kv ...any)
Infow(ctx context.Context, msg string, kv ...any)
Warnw(ctx context.Context, msg string, kv ...any)
Errorw(ctx context.Context, msg string, kv ...any)
Fatalw(ctx context.Context, msg string, kv ...any)
Sync(ctx context.Context) error
}
Logger is the SDK-wide logging interface for plugin runtime logs.
func Default ¶
func Default() Logger
Default returns the process-wide logger, initially a logger that discards records.
type MultiSink ¶
type MultiSink struct {
// contains filtered or unexported fields
}
MultiSink fans out writes to multiple sinks.
func NewMultiSink ¶
NewMultiSink snapshots the sink list and omits nil sinks.
type SinkBackend ¶
type SinkBackend struct {
// contains filtered or unexported fields
}
SinkBackend adapts a Sink to Backend.
func NewSinkBackend ¶
func NewSinkBackend(sink Sink) *SinkBackend
NewSinkBackend wraps sink; a nil sink discards records.