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 AsyncWriter
- 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 ¶
Normalises dynamic values to prevent fragmenting Sentry 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 ¶
Accepts zerolog-compatible names for backwards compatibility.
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 (*Logger) DebugContext ¶
func (*Logger) ErrorContext ¶
Use NoCapture(ctx) to suppress Sentry capture for expected errors.