logging

package
v0.33.5 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2026 License: MIT Imports: 9 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func BeforeSend

func BeforeSend(event *sentry.Event, hint *sentry.EventHint) *sentry.Event

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

func NoCapture(ctx context.Context) context.Context

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

func ParseLevel(s string) slog.Level

ParseLevel converts a string level name to slog.Level. Supports zerolog-compatible names for backwards compatibility.

func Setup

func Setup(level slog.Level, env string)

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

func Component(name string) *Logger

Component creates a component-scoped logger. The component name appears as a structured field, a Sentry tag, and a human-readable prefix.

func (*Logger) Debug

func (l *Logger) Debug(msg string, args ...any)

Debug logs at debug level (no Sentry capture).

func (*Logger) DebugContext

func (l *Logger) DebugContext(ctx context.Context, msg string, args ...any)

DebugContext logs at debug level with a context.

func (*Logger) Error

func (l *Logger) Error(msg string, args ...any)

Error logs at error level. Auto-captured to Sentry via the handler. Tags and fingerprint are injected automatically.

func (*Logger) ErrorContext

func (l *Logger) ErrorContext(ctx context.Context, msg string, args ...any)

ErrorContext logs at error level with a context. Use NoCapture(ctx) to suppress Sentry capture for expected errors.

func (*Logger) Fatal

func (l *Logger) Fatal(msg string, args ...any)

Fatal logs at error level, captures to Sentry, flushes, and exits.

func (*Logger) Info

func (l *Logger) Info(msg string, args ...any)

Info logs at info level (no Sentry capture).

func (*Logger) InfoContext

func (l *Logger) InfoContext(ctx context.Context, msg string, args ...any)

InfoContext logs at info level with a context.

func (*Logger) Warn

func (l *Logger) Warn(msg string, args ...any)

Warn logs at warn level (no Sentry capture by default).

func (*Logger) WarnContext

func (l *Logger) WarnContext(ctx context.Context, msg string, args ...any)

WarnContext logs at warn level with a context.

func (*Logger) With

func (l *Logger) With(args ...any) *Logger

With returns a new Logger that includes the given attributes on every subsequent log call. Useful for adding request-scoped fields.

Jump to

Keyboard shortcuts

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