Documentation
¶
Overview ¶
Package logging provides a unified slog + Sentry logging interface.
Every log call automatically includes a component tag for structured monitoring. Error-level calls auto-capture to Sentry via the sentry-go/slog handler. Use NoCapture in the context to suppress capture for expected errors.
Index ¶
- func BeforeSend(event *sentry.Event, hint *sentry.EventHint) *sentry.Event
- func NoCapture(ctx context.Context) context.Context
- func ParseLevel(s string) slog.Level
- func Setup(level slog.Level, env string)
- type Logger
- func (l *Logger) Debug(msg string, args ...any)
- func (l *Logger) DebugContext(ctx context.Context, msg string, args ...any)
- func (l *Logger) Error(msg string, args ...any)
- func (l *Logger) ErrorContext(ctx context.Context, msg string, args ...any)
- func (l *Logger) Fatal(msg string, args ...any)
- func (l *Logger) Info(msg string, args ...any)
- func (l *Logger) InfoContext(ctx context.Context, msg string, args ...any)
- func (l *Logger) Warn(msg string, args ...any)
- func (l *Logger) WarnContext(ctx context.Context, msg string, args ...any)
- func (l *Logger) With(args ...any) *Logger
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BeforeSend ¶
BeforeSend is a sentry.EventProcessor that normalises event messages by replacing UUIDs and bare numbers with placeholders. Install on sentry.Init to prevent dynamic values from fragmenting issue grouping.
func NoCapture ¶
NoCapture returns a derived context that suppresses Sentry capture for any ErrorContext call made with it. The suppression persists for the lifetime of the derived context — construct it inline so the scope is limited to one call:
log.ErrorContext(logging.NoCapture(ctx), "expected 404", "url", url, "error", err)
Do not store the derived context and reuse it, or all subsequent error log calls on that context will also be silently dropped from Sentry.
func ParseLevel ¶
ParseLevel converts a string level name to slog.Level. Supports zerolog-compatible names for backwards compatibility.
func Setup ¶
Setup configures the global slog default with both stdout output and Sentry capture. Call this after sentry.Init() during application startup.
In development, logs are human-readable text. In production, JSON. Error-level logs are auto-captured to Sentry with component tags and static fingerprints.
Types ¶
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger is a component-scoped structured logger. It rebuilds the underlying slog.Logger at emit time so it always picks up the current slog.Default() (i.e., the fanout handler installed by Setup after sentry.Init).
func Component ¶
Component creates a component-scoped logger. The component name appears as a structured field, a Sentry tag, and a human-readable prefix.
func (*Logger) DebugContext ¶
DebugContext logs at debug level with a context.
func (*Logger) Error ¶
Error logs at error level. Auto-captured to Sentry via the handler. Tags and fingerprint are injected automatically.
func (*Logger) ErrorContext ¶
ErrorContext logs at error level with a context. Use NoCapture(ctx) to suppress Sentry capture for expected errors.
func (*Logger) InfoContext ¶
InfoContext logs at info level with a context.
func (*Logger) WarnContext ¶
WarnContext logs at warn level with a context.