slogrollbar

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 9, 2023 License: MIT Imports: 6 Imported by: 0

README

slog: Rollbar handler

tag Go Version GoDoc Build Status Go report Coverage Contributors License

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

Contributors

💫 Show your support

Give a ⭐️ if this project helped you!

GitHub Sponsors

📝 License

Copyright © 2023 Samuel Berthe.

This project is MIT licensed.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultConverter

func DefaultConverter(loggerAttr []slog.Attr, record slog.Record) (map[string]any, error)

Types

type Converter

type Converter func(loggerAttr []slog.Attr, record slog.Record) (map[string]any, error)

type Option

type Option struct {
	// log level (default: debug)
	Level slog.Leveler

	// Rollbar client
	Client *rollbar.Client

	// optional: customize Rollbar event builder
	Converter Converter
}

func (Option) NewRollbarHandler

func (o Option) NewRollbarHandler() slog.Handler

type RollbarHandler

type RollbarHandler struct {
	// contains filtered or unexported fields
}

func (*RollbarHandler) Enabled

func (h *RollbarHandler) Enabled(_ context.Context, level slog.Level) bool

func (*RollbarHandler) Handle

func (h *RollbarHandler) Handle(ctx context.Context, record slog.Record) error

func (*RollbarHandler) WithAttrs

func (h *RollbarHandler) WithAttrs(attrs []slog.Attr) slog.Handler

func (*RollbarHandler) WithGroup

func (h *RollbarHandler) WithGroup(name string) slog.Handler

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL