log

package
v0.5.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 28, 2026 License: AGPL-3.0 Imports: 11 Imported by: 13

Documentation

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)

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
}

type ContextEnricher

type ContextEnricher func(context.Context) []Field

ContextEnricher extracts structured fields from a context. Registered via RegisterContextEnricher to break import cycles.

type Field

type Field struct {
	Key   string
	Value any
}

Field is a structured key/value pair attached to log records.

func Any

func Any(key string, value any) Field

func Bool

func Bool(key string, value bool) Field

func Duration

func Duration(key string, value time.Duration) Field

func Error

func Error(err error) Field

func Int

func Int(key string, value int) Field

func Int64

func Int64(key string, value int64) Field

func String

func String(key, value string) Field

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

func NewHCLBackend

func NewHCLBackend(logger hclog.Logger) *HCLBackend

func (*HCLBackend) Named

func (b *HCLBackend) Named(name string) *HCLBackend

func (*HCLBackend) SetLevel

func (b *HCLBackend) SetLevel(level Level)

func (*HCLBackend) Sync

func (b *HCLBackend) Sync(_ context.Context) error

func (*HCLBackend) Write

func (b *HCLBackend) Write(_ context.Context, record Record) error

type Level

type Level int32

Level is the logging severity level.

const (
	LevelTrace Level = iota
	LevelDebug
	LevelInfo
	LevelWarn
	LevelError
	LevelFatal
)

func ParseLevel

func ParseLevel(s string) (Level, error)

func (Level) String

func (l Level) String() string

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

func (*LevelController) Enabled

func (c *LevelController) Enabled(level Level) bool

func (*LevelController) Level

func (c *LevelController) Level() Level

func (*LevelController) Set

func (c *LevelController) Set(level Level)

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

func New

func New(cfg Config) Logger

func NewNop

func NewNop() Logger

type MultiSink

type MultiSink struct {
	// contains filtered or unexported fields
}

MultiSink fans out writes to multiple sinks.

func NewMultiSink

func NewMultiSink(sinks ...Sink) *MultiSink

func (*MultiSink) Write

func (m *MultiSink) Write(ctx context.Context, record Record) error

type Record

type Record struct {
	Timestamp time.Time
	Level     Level
	Logger    string
	Message   string
	Fields    []Field
}

Record is the normalized representation of a log entry.

func (Record) ToMap

func (r Record) ToMap() map[string]any

type Sink

type Sink interface {
	Write(ctx context.Context, record Record) error
}

Sink receives normalized log records.

type SinkBackend

type SinkBackend struct {
	// contains filtered or unexported fields
}

SinkBackend adapts a Sink to Backend.

func NewSinkBackend

func NewSinkBackend(sink Sink) *SinkBackend

func (*SinkBackend) Sync

func (b *SinkBackend) Sync(_ context.Context) error

func (*SinkBackend) Write

func (b *SinkBackend) Write(ctx context.Context, record Record) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL