core

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 21, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AsyncCore

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

func (*AsyncCore) Dropped

func (c *AsyncCore) Dropped() uint64

func (*AsyncCore) Enabled

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

func (*AsyncCore) Sync

func (c *AsyncCore) Sync() error

func (*AsyncCore) With

func (c *AsyncCore) With(fields []field.Field) Core

func (*AsyncCore) Write

func (c *AsyncCore) Write(event Event) error

type AsyncPolicy

type AsyncPolicy uint8
const (
	AsyncBlock AsyncPolicy = iota
	AsyncDropNewest
	AsyncDropOldest
)

type AtomicLevel

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

AtomicLevel is a dynamically adjustable minimum log level.

func NewAtomicLevel

func NewAtomicLevel(level Level) *AtomicLevel

func (*AtomicLevel) Enabled

func (a *AtomicLevel) Enabled(level Level) bool

func (*AtomicLevel) Level

func (a *AtomicLevel) Level() Level

func (*AtomicLevel) Set

func (a *AtomicLevel) Set(level Level)

type Core

type Core interface {
	Enabled(Level) bool
	Write(Event) error
	With([]field.Field) Core
	Sync() error
}

Core is the backend contract for loggers, encoders, fan-out cores, filters, and external logger adapters.

func NewAsyncCore

func NewAsyncCore(next Core, buffer int, policy AsyncPolicy, observer Observer) Core

func NewFilterCore

func NewFilterCore(next Core, leveler LevelEnabler) Core

func NewHookCore

func NewHookCore(next Core, observer Observer) Core

func NewSamplerCore

func NewSamplerCore(next Core, first, thereafter uint64) Core

func NewTeeCore

func NewTeeCore(cores ...Core) Core

type DropObserver

type DropObserver interface {
	OnDrop(Event)
}

type Encoder

type Encoder interface {
	Encode(dst []byte, event Event) []byte
}

Encoder converts an event to bytes. Implementations may reuse dst.

type Event

type Event struct {
	// Ctx is the context the event was logged with, or nil for the plain
	// (non-context) logging path. Context-aware cores (e.g. the slog adapter)
	// should fall back to context.Background() when it is nil. Carried for
	// backends that read request-scoped values such as OTel trace context.
	Ctx context.Context

	Time    time.Time
	Level   Level
	Message string

	Context []field.Field
	Fields  []field.Field
}

Event is a structured log record passed from Logger to Core.

type FilterCore

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

func (*FilterCore) Enabled

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

func (*FilterCore) Sync

func (c *FilterCore) Sync() error

func (*FilterCore) With

func (c *FilterCore) With(fields []field.Field) Core

func (*FilterCore) Write

func (c *FilterCore) Write(event Event) error

type HookCore

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

func (*HookCore) Enabled

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

func (*HookCore) Sync

func (c *HookCore) Sync() error

func (*HookCore) With

func (c *HookCore) With(fields []field.Field) Core

func (*HookCore) Write

func (c *HookCore) Write(event Event) error

type Level

type Level int8

Level is a logging severity.

const (
	TraceLevel    Level = -2
	DebugLevel    Level = -1
	InfoLevel     Level = 0
	WarnLevel     Level = 1
	ErrorLevel    Level = 2
	CriticalLevel Level = 3
)

func (Level) String

func (l Level) String() string

type LevelEnabler

type LevelEnabler interface {
	Enabled(Level) bool
}

LevelEnabler decides whether a level should be written.

type LevelReader

type LevelReader interface {
	LevelEnabler
	Level() Level
}

LevelReader is an optional LevelEnabler that reports its current minimum level. *AtomicLevel implements it; Logger.Level uses it to read dynamic levelers without probing.

type NopCore

type NopCore struct{}

NopCore drops every event.

func (NopCore) Enabled

func (NopCore) Enabled(Level) bool

func (NopCore) Sync

func (NopCore) Sync() error

func (NopCore) With

func (n NopCore) With([]field.Field) Core

func (NopCore) Write

func (NopCore) Write(Event) error

type Observer

type Observer interface {
	OnWrite(Event, error)
}

type SamplerCore

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

func (*SamplerCore) Enabled

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

func (*SamplerCore) Sync

func (c *SamplerCore) Sync() error

func (*SamplerCore) With

func (c *SamplerCore) With(fields []field.Field) Core

func (*SamplerCore) Write

func (c *SamplerCore) Write(event Event) error

type TeeCore

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

func (*TeeCore) Enabled

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

func (*TeeCore) Sync

func (c *TeeCore) Sync() error

func (*TeeCore) With

func (c *TeeCore) With(fields []field.Field) Core

func (*TeeCore) Write

func (c *TeeCore) Write(event Event) error

Jump to

Keyboard shortcuts

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