logger

package
v0.99.0 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendCtx added in v0.99.0

func AppendCtx(ctx context.Context, attrs ...slog.Attr) context.Context

AppendCtx stores slog attributes in context for the ContextHandler to extract. It copies the existing slice to avoid mutating a parent context's backing array when multiple goroutines fork from the same context.

func Fatal added in v0.99.0

func Fatal(logger *slog.Logger, msg string, args ...any)

Fatal logs at error level and exits.

func InitLogger

func InitLogger(cfg Config) *slog.Logger

Types

type Config

type Config struct {
	// log level - debug, info, warning, error, fatal
	Level string `yaml:"level" mapstructure:"level" default:"info" json:"level,omitempty"`

	// format strategy - plain, json
	Format string `yaml:"format" mapstructure:"format" default:"json" json:"format,omitempty"`

	// audit system events - none(default), stdout, db
	AuditEvents string `yaml:"audit_events" mapstructure:"audit_events" default:"none" json:"audit_events,omitempty"`

	// IgnoredAuditEvents contains list of events which should be ignored in audit logs
	IgnoredAuditEvents []string `yaml:"ignored_audit_events" mapstructure:"ignored_audit_events" json:"ignored_audit_events,omitempty"`
}

type ContextHandler added in v0.99.0

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

ContextHandler wraps any slog.Handler and auto-appends attributes stored in the context via AppendCtx. This enables request-scoped fields (request_id, method, etc.) to appear in every log line without passing them explicitly.

func NewContextHandler added in v0.99.0

func NewContextHandler(inner slog.Handler) *ContextHandler

func (*ContextHandler) Enabled added in v0.99.0

func (h *ContextHandler) Enabled(ctx context.Context, level slog.Level) bool

func (*ContextHandler) Handle added in v0.99.0

func (h *ContextHandler) Handle(ctx context.Context, r slog.Record) error

func (*ContextHandler) WithAttrs added in v0.99.0

func (h *ContextHandler) WithAttrs(attrs []slog.Attr) slog.Handler

func (*ContextHandler) WithGroup added in v0.99.0

func (h *ContextHandler) WithGroup(name string) slog.Handler

Jump to

Keyboard shortcuts

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