Documentation
¶
Overview ¶
Package slogalert provides an slog.Handler that mirrors error-level records to a chat webhook (Google Chat, Slack, or any JSON endpoint) while passing every record to an inner handler.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GoogleChatText ¶
GoogleChatText renders a plain-text alert as {"text": ...}, the shape Google Chat and Slack incoming webhooks both accept.
Types ¶
type Event ¶
type Event struct {
Time time.Time
Level slog.Level
Message string
Service string
Attrs []slog.Attr
}
Event is the alert payload: the triggering record plus merged attrs.
type FormatFunc ¶
FormatFunc renders an Event into a webhook request body.
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler decorates an inner handler, mirroring records at or above MinLevel to the webhook.
func (*Handler) Handle ¶
Handle passes the record to inner and, at or above MinLevel, sends an alert.
type Options ¶
type Options struct {
WebhookURL string
ServiceName string
// MinLevel is the level at or above which records alert.
// Nil defaults to slog.LevelError.
MinLevel slog.Leveler
// Debounce collapses repeat alerts with the same message.
// Zero defaults to one minute; negative disables debouncing.
Debounce time.Duration
// Format renders the webhook request body. Nil defaults to GoogleChatText.
Format FormatFunc
// Client posts the alert. Nil defaults to a client with a 10s timeout.
Client *http.Client
}
Options configures a Handler. Only WebhookURL is required.