Documentation
¶
Index ¶
- type BatchHandler
- type Daemon
- type MessageFormatter
- func (f *MessageFormatter) Active(msg string) string
- func (f *MessageFormatter) Complete(msg string) string
- func (f *MessageFormatter) Component(msg string) string
- func (f *MessageFormatter) Disabled(msg string) string
- func (f *MessageFormatter) Fail(msg string) string
- func (f *MessageFormatter) Inactive(msg string) string
- func (f *MessageFormatter) Ok(msg string) string
- func (f *MessageFormatter) Seed(msg string) string
- func (f *MessageFormatter) Start(msg string) string
- func (f *MessageFormatter) Warn(msg string) string
- func (f *MessageFormatter) WithComponent(name, emoji string) *MessageFormatter
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 ¶
Enabled implements the slog.Handler interface. It consults the config provider to get the current logging level.
func (*BatchHandler) Handle ¶
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.
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 ¶
New creates a new Daemon. It creates a channel for slog.Records and establishes a database connection.
func (*Daemon) Chan ¶
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 ¶
InsertLogs writes a batch of pre-processed dbLogEntry items to the database.
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