Skip to content

SkYNewZ/slog-pushover

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

slog: Pushover handler

tag Go Version GoDoc Go report License

A Pushover Handler for slog Go library. Inspired from samber' s slog repositories

🚀 Install

go get github.com/SkYNewZ/slog-pushover

Compatibility: go >= 1.21

💡 Usage

GoDoc: https://pkg.go.dev/github.com/skynewz/slog-pushover

Handler options

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
}

Example

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")
}

👤 Contributors

Contributors

📝 License

Copyright © 2023 Quentin Lemaire.

This project is MIT licensed.