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 ¶
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 ¶
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.
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. |