slog: Rollbar handler
A Rollbar Handler for slog Go library.
See also:
🚀 Install
go get github.com/samber/slog-rollbar
Compatibility: go >= 1.21
No breaking changes will be made to exported APIs before v2.0.0.
💡 Usage
GoDoc: https://pkg.go.dev/github.com/samber/slog-rollbar
Handler options
type Option struct {
// log level (default: debug)
Level slog.Leveler
// Rollbar client
Client *rollbar.Client
// optional: customize Rollbar event builder
Converter Converter
}
Example
import (
"fmt"
"time"
"github.com/rollbar/rollbar-go"
slogrollbar "github.com/samber/slog-rollbar"
"log/slog"
)
func main() {
token := "xxxxx"
env := "production"
version := "v1"
host := "127.0.0.1"
project := "samber/slog-rollbar/example"
client := rollbar.NewAsync(token, env, version, host, project)
defer client.Close()
logger := slog.New(slogrollbar.Option{Level: slog.LevelDebug, Client: client}.NewRollbarHandler())
logger.
With(
slog.Group("user",
slog.String("id", "user-123"),
slog.Time("created_at", time.Now()),
),
).
With("error", fmt.Errorf("an error")).
Error("a message")
}
🤝 Contributing
Don't hesitate ;)
# Install some dev dependencies
make tools
# Run tests
make test
# or
make watch-test
👤 Contributors
💫 Show your support
Give a ⭐️ if this project helped you!
📝 License
Copyright © 2023 Samuel Berthe.
This project is MIT licensed.