Help us shape the future of Go! Take the 2026 Go Developer Survey

logging

package
v0.30.0 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package logging holds log/slog handlers shared by Vukem apps.

Dedup keeps a burst of identical errors from flooding logs and alerts: the first record of a kind is written at once, the repeats inside the window are counted, and one "repeated" record with the count closes the window.

d := logging.NewDedup(base, logging.DedupOptions{Window: time.Minute})
log := slog.New(d)
defer d.Close(ctx)

See https://github.com/AlexGalhardo/vukem/blob/main/docs/subsystems.md#logging--observability.

Index

Constants

View Source
const DefaultDedupWindow = time.Minute

DefaultDedupWindow is the window NewDedup uses when none is set.

Variables

This section is empty.

Functions

This section is empty.

Types

type Dedup

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

Dedup is a slog.Handler that suppresses repeated identical records. Two records are identical when they share the level, the message, the handler's attributes and groups, and the values of the "event", "error" and "err" attributes.

The first record of a window is passed to the next handler at once. When the window ends, if repeats were suppressed, a record with the message "repeated" carries "message" (the original message), "count" (the suppressed repeats) and "window". A repeat after the window starts a new one. Summaries are written by a timer per window, or by Close.

Dedup is safe for concurrent use; handlers derived with WithAttrs and WithGroup share its state.

func NewDedup

func NewDedup(next slog.Handler, opts DedupOptions) *Dedup

NewDedup returns a Dedup writing to next.

func (*Dedup) Close

func (d *Dedup) Close(ctx context.Context) error

Close writes the pending "repeated" summaries; later records pass through unchanged. It is idempotent and returns the first error of the next handler, or ctx's error when ctx ends first.

func (*Dedup) Enabled

func (d *Dedup) Enabled(ctx context.Context, level slog.Level) bool

Enabled reports whether the next handler handles level.

func (*Dedup) Handle

func (d *Dedup) Handle(ctx context.Context, r slog.Record) error

Handle writes r unless it repeats a record seen in the current window.

func (*Dedup) WithAttrs

func (d *Dedup) WithAttrs(attrs []slog.Attr) slog.Handler

WithAttrs returns a handler whose records carry attrs; it shares the window state with d.

func (*Dedup) WithGroup

func (d *Dedup) WithGroup(name string) slog.Handler

WithGroup returns a handler that nests later attributes under name; it shares the window state with d.

type DedupOptions

type DedupOptions struct {
	// Window is how long repeats of a record are counted instead of
	// written (default [DefaultDedupWindow]).
	Window time.Duration
	// MinLevel is the lowest level deduplicated (default slog.LevelError);
	// lower records always pass through.
	MinLevel slog.Leveler
}

DedupOptions configures NewDedup.

Directories

Path Synopsis
Package telegram is a log/slog handler that sends records to Telegram chats, ported from the maintainer's TypeScript telegram-logger.
Package telegram is a log/slog handler that sends records to Telegram chats, ported from the maintainer's TypeScript telegram-logger.

Jump to

Keyboard shortcuts

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