go.bigb.es/auxilia
Index
- func DefaultLevelColors() map[slog.Level]Color
- func Err(err error) slog.Attr
- func ErrAttr(key string, err error) slog.Attr
- func NewJSONHandler(opts ...Option) slog.Handler
- func NewTextHandler(opts ...Option) slog.Handler
- type BufferHandler
- func NewBufferHandler(inner slog.Handler, opts ...Option) *BufferHandler
- func (*BufferHandler) Buffer() *RingBuffer[StoredRecord]
- func (*BufferHandler) Enabled(_ context.Context, _ slog.Level) bool
- func (*BufferHandler) Handle(ctx context.Context, r slog.Record) error
- func (*BufferHandler) Records() []StoredRecord
- func (*BufferHandler) RecordsByLevel(level slog.Level) []StoredRecord
- func (*BufferHandler) RecordsSince(t time.Time) []StoredRecord
- func (*BufferHandler) Replay(ctx context.Context, target slog.Handler) error
- func (*BufferHandler) WithAttrs(attrs []slog.Attr) slog.Handler
- func (*BufferHandler) WithGroup(name string) slog.Handler
- type Color
- const Black
- const Blue
- const Bold
- const BrightBlue
- const BrightCyan
- const BrightGreen
- const BrightMagenta
- const BrightRed
- const BrightWhite
- const BrightYellow
- const Cyan
- const Faint
- const Gray
- const Green
- const Italic
- const Magenta
- const Red
- const Reset
- const White
- const Yellow
- func (Color) String() string
- func (Color) Wrap(s string) string
- type MaskRule
- type MultiHandler
- func NewMultiHandler(handlers ...slog.Handler) *MultiHandler
- func (*MultiHandler) Enabled(ctx context.Context, level slog.Level) bool
- func (*MultiHandler) Handle(ctx context.Context, r slog.Record) error
- func (*MultiHandler) WithAttrs(attrs []slog.Attr) slog.Handler
- func (*MultiHandler) WithGroup(name string) slog.Handler
- type Option
- func WithBufferSize(size int) Option
- func WithExpandErrors(expand bool) Option
- func WithFullStacktrace(full bool) Option
- func WithLevel(l slog.Leveler) Option
- func WithLevelColors(colors map[slog.Level]Color) Option
- func WithMask(pattern string, replacement string) Option
- func WithMaskKeys(keys ...string) Option
- func WithMaskPartial(pattern string, keepPrefix int) Option
- func WithNoColor(noColor bool) Option
- func WithReplaceAttr(f func(groups []string, a slog.Attr) slog.Attr) Option
- func WithSource(enabled bool) Option
- func WithTimeFormat(format string) Option
- func WithWriter(w io.Writer) Option
- type RingBuffer
- type StoredRecord
- type TintHandler
- func NewTintHandler(opts ...Option) *TintHandler
- func (*TintHandler) Enabled(_ context.Context, level slog.Level) bool
- func (*TintHandler) Handle(_ context.Context, r slog.Record) error
- func (*TintHandler) WithAttrs(attrs []slog.Attr) slog.Handler
- func (*TintHandler) WithGroup(name string) slog.Handler
Functions
func DefaultLevelColors() map[slog.Level]Color
Err wraps an error for logging with red color highlighting. Use this when logging errors to make them visually distinct:
logger.Error("failed", scribe.Err(err))
If the error is a culpa error, its details (hint, code, etc.) and stacktrace will be extracted and formatted.
ErrAttr is like Err but allows specifying a custom key.
logger.Error("failed", scribe.ErrAttr("cause", err))
func NewJSONHandler(opts ...Option) slog.Handler
NewJSONHandler creates a JSON handler with the scribe options API. This is a convenience wrapper around slog.JSONHandler for consistency.
func NewTextHandler(opts ...Option) slog.Handler
NewTextHandler creates a text handler with the scribe options API. This is a convenience wrapper around slog.TextHandler for consistency.
Types
type BufferHandler struct { // contains filtered or unexported fields }
BufferHandler wraps another handler and stores all records in a ring buffer. Records are stored regardless of level filtering applied by the inner handler.
func NewBufferHandler(inner slog.Handler, opts ...Option) *BufferHandler
NewBufferHandler creates a buffering wrapper around another handler.
func (h *BufferHandler) Buffer() *RingBuffer[StoredRecord]
Buffer returns the underlying ring buffer for direct access.
func (h *BufferHandler) Enabled(_ context.Context, _ slog.Level) bool
Enabled implements slog.Handler. Always returns true to capture all records in the buffer.
func (h *BufferHandler) Handle(ctx context.Context, r slog.Record) error
Handle implements slog.Handler.
func (h *BufferHandler) Records() []StoredRecord
Records returns all stored records.
func (h *BufferHandler) RecordsByLevel(level slog.Level) []StoredRecord
RecordsByLevel returns records matching the given level.
func (h *BufferHandler) RecordsSince(t time.Time) []StoredRecord
RecordsSince returns records from the given time onwards.
func (h *BufferHandler) Replay(ctx context.Context, target slog.Handler) error
Replay sends all buffered records to another handler.
func (h *BufferHandler) WithAttrs(attrs []slog.Attr) slog.Handler
WithAttrs implements slog.Handler.
func (h *BufferHandler) WithGroup(name string) slog.Handler
WithGroup implements slog.Handler.
type Color string
Color represents an ANSI color code.
const ( Reset Color = "\033[0m" Bold Color = "\033[1m" Faint Color = "\033[2m" Italic Color = "\033[3m" Black Color = "\033[30m" Red Color = "\033[31m" Green Color = "\033[32m" Yellow Color = "\033[33m" Blue Color = "\033[34m" Magenta Color = "\033[35m" Cyan Color = "\033[36m" White Color = "\033[37m" Gray Color = "\033[90m" // Bright variants BrightRed Color = "\033[91m" BrightGreen Color = "\033[92m" BrightYellow Color = "\033[93m" BrightBlue Color = "\033[94m" BrightMagenta Color = "\033[95m" BrightCyan Color = "\033[96m" BrightWhite Color = "\033[97m" )
ANSI color codes.
type MaskRule struct { Pattern *regexp.Regexp Replacement string KeepPrefix int // If > 0, keep first N chars and append Replacement }
MaskRule defines a pattern for masking sensitive values.
type MultiHandler struct { // contains filtered or unexported fields }
MultiHandler fans out log records to multiple handlers.
func NewMultiHandler(handlers ...slog.Handler) *MultiHandler
NewMultiHandler creates a handler that writes to all given handlers.
func (h *MultiHandler) Enabled(ctx context.Context, level slog.Level) bool
Enabled implements slog.Handler. Returns true if any inner handler is enabled for the level.
func (h *MultiHandler) Handle(ctx context.Context, r slog.Record) error
Handle implements slog.Handler. Writes to all enabled handlers, collecting any errors.
func (h *MultiHandler) WithAttrs(attrs []slog.Attr) slog.Handler
WithAttrs implements slog.Handler.
func (h *MultiHandler) WithGroup(name string) slog.Handler
WithGroup implements slog.Handler.
type Option func(*options)
Option configures a Handler.
func WithBufferSize(size int) Option
WithBufferSize sets the circular buffer capacity (number of records).
func WithExpandErrors(expand bool) Option
WithExpandErrors controls whether error details are expanded into separate fields (err.msg, err.code, etc.) or kept as a single group. Default is true (expanded).
func WithFullStacktrace(full bool) Option
WithFullStacktrace controls whether full stacktraces are shown. When false (default), only the first frame (file:line) is shown. When true, the complete stacktrace is displayed.
func WithLevelColors(colors map[slog.Level]Color) Option
WithLevelColors sets custom colors for log levels.
WithMask adds a masking rule for sensitive data. Pattern is a regex that matches against the full key path (e.g., "user.password"). Replacement is the string to show instead of the actual value (default: "***").
Example patterns:
- `(?i)password` - matches any key containing "password" (case-insensitive)
- `(?i)(secret|token|key)` - matches keys with secret, token, or key
- `^user\..*_secret$` - matches user.api_secret, user.client_secret, etc.
- `\[\d+\]\.apiKey` - matches items[0].apiKey, items[1].apiKey, etc.
func WithMaskKeys(keys ...string) Option
WithMaskKeys adds exact key masking (case-insensitive). This is a convenience wrapper around WithMask for simple cases.
Example:
WithMaskKeys("password", "secret", "token", "apiKey")
func WithMaskPartial(pattern string, keepPrefix int) Option
WithMaskPartial adds a partial masking rule that keeps the first N characters. Useful for tokens, IDs, or hashes where you want to see a prefix for debugging.
Example:
WithMaskPartial(`(?i)token`, 6) // "bearer-abc123xyz" → "bearer***" WithMaskPartial(`(?i)hash`, 8) // "0xabcdef123456" → "0xabcdef***"
func WithReplaceAttr(f func(groups []string, a slog.Attr) slog.Attr) Option
WithReplaceAttr sets the attribute replacement function. This function is called for each attribute before it is formatted.
func WithSource(enabled bool) Option
WithSource enables source code location in log output.
func WithTimeFormat(format string) Option
WithTimeFormat sets the time format for tint output. Uses Go's time format strings (e.g., time.RFC3339, time.Kitchen).
type RingBuffer[T any] struct { // contains filtered or unexported fields }
RingBuffer is a generic circular buffer.
func NewRingBuffer[T any](capacity int) *RingBuffer[T]
NewRingBuffer creates a new ring buffer with the given capacity.
func (r *RingBuffer[T]) Clear()
Clear removes all items from the buffer.
func (r *RingBuffer[T]) Filter(pred func(T) bool) []T
Filter returns items matching the predicate.
func (r *RingBuffer[T]) Len() int
Len returns the current number of items.
func (r *RingBuffer[T]) Push(item T)
Push adds an item to the buffer, evicting the oldest if full.
func (r *RingBuffer[T]) Snapshot() []T
Snapshot returns a copy of all items in chronological order.
type StoredRecord struct { Time time.Time Level slog.Level Message string Attrs []slog.Attr PC uintptr Groups []string }
StoredRecord holds a captured log record for later retrieval.
func FromSlogRecord(r slog.Record, groups []string) StoredRecord
FromSlogRecord creates a StoredRecord from an slog.Record.
func (s StoredRecord) ToSlogRecord() slog.Record
ToSlogRecord converts back to an slog.Record (for replay).
type TintHandler struct { // contains filtered or unexported fields }
TintHandler is a pretty-printing slog.Handler for terminal output.
func NewTintHandler(opts ...Option) *TintHandler
NewTintHandler creates a new pretty-printing handler for terminal output.
func (h *TintHandler) Enabled(_ context.Context, level slog.Level) bool
Enabled implements slog.Handler.
func (h *TintHandler) Handle(_ context.Context, r slog.Record) error
Handle implements slog.Handler.
func (h *TintHandler) WithAttrs(attrs []slog.Attr) slog.Handler
WithAttrs implements slog.Handler.
func (h *TintHandler) WithGroup(name string) slog.Handler
WithGroup implements slog.Handler.
DefaultLevelColors returns sensible default colors for log levels.