logging

package
v0.33.13 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2026 License: MIT Imports: 12 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

Normalises dynamic values to prevent fragmenting Sentry 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

Accepts zerolog-compatible names for backwards compatibility.

func Setup

func Setup(level slog.Level, env string)

Call after sentry.Init(). Development uses synchronous text for deterministic test output; production uses async JSON so no goroutine can wedge in slog.Handler.Handle on backpressured stdout.

Types

type AsyncWriter added in v0.33.8

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

Drops on full buffer rather than blocking. Blocking the caller has been observed to wedge goroutines holding DB transactions, leaving Postgres sessions `idle in transaction (aborted)` for tens of minutes (HOVER-K* class of incidents).

func NewAsyncWriter added in v0.33.8

func NewAsyncWriter(underlying io.Writer, bufferSize int) *AsyncWriter

8192 default absorbs burst spikes while bounding memory under sustained backpressure.

func StdoutAsync added in v0.33.8

func StdoutAsync() *AsyncWriter

nil if Setup has not been called or async logging is disabled (development).

func (*AsyncWriter) Close added in v0.33.8

func (a *AsyncWriter) Close()

Idempotent and safe to call concurrently with Write.

func (*AsyncWriter) Dropped added in v0.33.8

func (a *AsyncWriter) Dropped() uint64

func (*AsyncWriter) Write added in v0.33.8

func (a *AsyncWriter) Write(p []byte) (int, error)

Returned n is always len(p) so slog handlers don't treat a drop as a partial write.

func (*AsyncWriter) Written added in v0.33.8

func (a *AsyncWriter) Written() uint64

type Logger

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

Rebuilds the underlying slog.Logger at emit time so it picks up the fanout handler installed by Setup after sentry.Init.

func Component

func Component(name string) *Logger

func (*Logger) Debug

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

func (*Logger) DebugContext

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

func (*Logger) Error

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

func (*Logger) ErrorContext

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

Use NoCapture(ctx) to suppress Sentry capture for expected errors.

func (*Logger) Fatal

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

func (*Logger) Info

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

func (*Logger) InfoContext

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

func (*Logger) Warn

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

func (*Logger) WarnContext

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

func (*Logger) With

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

Jump to

Keyboard shortcuts

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