A Pushover Handler for slog Go library. Inspired from samber' s slog repositories
go get github.com/SkYNewZ/slog-pushover
Compatibility: go >= 1.21
GoDoc: https://pkg.go.dev/github.com/skynewz/slog-pushover
type Options struct {
Level slog.Leveler // minimum level of messages to log (default: slog.LevelDebug)
Token string // Pushover application token
Recipient string // Pushover user/group key
Message *pushover.Message // optional: customize Pushover message. 'Message' will be replaced by the log message
Converter Converter // optional: customize Pushover message builder
// optional: see slog.HandlerOptions
AddSource bool
ReplaceAttr func(groups []string, a slog.Attr) slog.Attr
}
package main
func main() {
handler := slogpushover.NewHandler(&slogpushover.Options{
Level: slog.LevelDebug,
Token: os.Getenv("PUSHOVER_TOKEN"),
Recipient: os.Getenv("PUSHOVER_RECIPIENT"),
Message: nil, // You can customize the message details
Converter: nil,
AddSource: true,
ReplaceAttr: nil,
})
logger := slog.New(handler)
logger = logger.With("release", "v1.0.0")
logger.
With(
slog.Group("user",
slog.String("id", "user-123"),
slog.Time("created_at", time.Now().AddDate(0, 0, -1)),
),
).
With("environment", "dev").
With("error", fmt.Errorf("an error")).
Error("A message")
}
Copyright © 2023 Quentin Lemaire.
This project is MIT licensed.