logging

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewTerminalHandler

func NewTerminalHandler() slog.Handler

NewTerminalHandler creates a terminal handler with color support if output is a TTY. This provides consistent terminal logging whether Sentry is enabled or not.

When output is directed to a terminal (TTY), it uses colorized output via tint for better readability during development. When output is redirected to files or pipes, it uses plain text for better compatibility with log aggregation tools.

Types

type MultiHandler

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

MultiHandler sends log records to multiple handlers simultaneously. This allows us to log to both Sentry and terminal when Sentry is enabled, providing both error tracking and local development visibility.

func NewMultiHandler

func NewMultiHandler(handlers ...slog.Handler) *MultiHandler

NewMultiHandler creates a new MultiHandler that forwards log records to all provided handlers. Each handler will receive the same log record, allowing for different processing strategies (e.g., one for Sentry error tracking, one for terminal output).

func (*MultiHandler) Enabled

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

Enabled reports whether the handler handles records at the given level. It returns true if any of the underlying handlers handle the level. This ensures that log records are processed if at least one handler can handle them.

func (*MultiHandler) Handle

func (h *MultiHandler) Handle(ctx context.Context, record slog.Record) error

Handle forwards the log record to all underlying handlers. If a handler fails, processing continues with the remaining handlers to ensure that logging failures don't cascade and break other outputs.

func (*MultiHandler) WithAttrs

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

WithAttrs returns a new MultiHandler whose handlers have the given attributes. This method ensures that attributes are propagated to all underlying handlers, maintaining consistency across different output destinations.

func (*MultiHandler) WithGroup

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

WithGroup returns a new MultiHandler whose handlers have the given group name. This method ensures that grouping is applied consistently across all handlers, maintaining log structure regardless of output destination.

Jump to

Keyboard shortcuts

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