log

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: May 22, 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 BatchHandler

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

BatchHandler is a lightweight slog.Handler that sends records to a channel for batched processing.

func NewBatchHandler

func NewBatchHandler(configProvider *config.Provider, recordChan chan<- slog.Record, daemonCtx context.Context) *BatchHandler

NewBatchHandler creates a new BatchHandler.

configProvider: An instance of the configuration provider for dynamic log levels. recordChan: The write-end of a buffered channel where slog.Records will be sent. daemonCtx: Context from daemon to detect shutdown state. If any parameter is nil, this function will panic.

func (*BatchHandler) Enabled

func (h *BatchHandler) Enabled(_ context.Context, level slog.Level) bool

Enabled implements the slog.Handler interface. It consults the config provider to get the current logging level.

func (*BatchHandler) Handle

func (h *BatchHandler) Handle(_ context.Context, r slog.Record) error

Handle implements the slog.Handler interface. It attempts to send the log record to the buffered channel with these behaviors: 1. First checks if daemon is shutting down (fast path) 2. Then attempts non-blocking channel send 3. Returns error if either:

  • Daemon is shutting down (highest priority)
  • Channel is full (secondary)

Note: The select statement evaluates both cases simultaneously, so we must check ctx.Done() first to ensure proper shutdown behavior.

func (*BatchHandler) WithAttrs

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

func (*BatchHandler) WithGroup

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

WithGroup implements the slog.Handler interface. TODO implement

type Daemon

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

Daemon consumes slog.Records from a channel and writes them to a DB. It owns the channel and the database connection.

func New

func New(configProvider *config.Provider, opLogger *slog.Logger, db db.DbLog) (*Daemon, error)

New creates a new Daemon. It creates a channel for slog.Records and establishes a database connection.

func (*Daemon) Chan

func (ld *Daemon) Chan() (chan<- slog.Record, context.Context)

Chan returns the write-end of the channel and the daemon's context. The context can be used to check if the daemon is shutting down.

func (*Daemon) InsertLogs

func (ld *Daemon) InsertLogs(ctx context.Context, batch []db.Log) error

InsertLogs writes a batch of pre-processed dbLogEntry items to the database.

func (*Daemon) Name

func (ld *Daemon) Name() string

Name returns the constant name of this daemon type.

func (*Daemon) Start

func (ld *Daemon) Start() error

Start begins the daemon's log processing goroutine.

func (*Daemon) Stop

func (ld *Daemon) Stop(ctx context.Context) error

Stop gracefully shuts down the daemon.

type MessageFormatter

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

MessageFormatter provides consistent log message formatting

func NewMessageFormatter

func NewMessageFormatter() *MessageFormatter

NewMessageFormatter creates a new formatter instance

func (*MessageFormatter) Active

func (f *MessageFormatter) Active(msg string) string

func (*MessageFormatter) Complete

func (f *MessageFormatter) Complete(msg string) string

func (*MessageFormatter) Component

func (f *MessageFormatter) Component(msg string) string

func (*MessageFormatter) Disabled

func (f *MessageFormatter) Disabled(msg string) string

func (*MessageFormatter) Fail

func (f *MessageFormatter) Fail(msg string) string

func (*MessageFormatter) Inactive

func (f *MessageFormatter) Inactive(msg string) string

func (*MessageFormatter) Ok

func (f *MessageFormatter) Ok(msg string) string

func (*MessageFormatter) Seed

func (f *MessageFormatter) Seed(msg string) string

func (*MessageFormatter) Start

func (f *MessageFormatter) Start(msg string) string

func (*MessageFormatter) Warn

func (f *MessageFormatter) Warn(msg string) string

func (*MessageFormatter) WithComponent

func (f *MessageFormatter) WithComponent(name, emoji string) *MessageFormatter

WithComponent sets the component name and emoji

Jump to

Keyboard shortcuts

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