rollrus: github.com/heroku/rollrus Index | Examples | Files

package rollrus

import "github.com/heroku/rollrus"

Index

Examples

Package Files

doc.go hook.go options.go rollrus.go

func ReportPanic Uses

func ReportPanic(token, env string)

ReportPanic attempts to report the panic to Rollbar using the provided client and then re-panic. If it can't report the panic it will print an error to stderr.

func SetupLogging Uses

func SetupLogging(token, env string)

SetupLogging for use on Heroku. If token is not an empty string a Rollbar hook is added with the environment set to env. The log formatter is set to a TextFormatter with timestamps disabled.

Code:

SetupLogging("some-long-token", "staging")

// This will not be reported to Rollbar
logrus.Info("OHAI")

// This will be reported to Rollbar
logrus.WithFields(logrus.Fields{"hi": "there"}).Fatal("The end.")

func SetupLoggingForLevels Uses

func SetupLoggingForLevels(token, env string, levels []logrus.Level)

SetupLoggingForLevels works like SetupLogging, but allows you to set the levels on which to trigger this hook.

type Hook Uses

type Hook struct {
    *rollbar.Client
    // contains filtered or unexported fields
}

Hook is a wrapper for the Rollbar Client and is usable as a logrus.Hook.

func NewHook Uses

func NewHook(token string, env string, opts ...OptionFunc) *Hook

NewHook creates a hook that is intended for use with your own logrus.Logger instance. Uses the default report levels defined in wellKnownErrorFields.

Code:

log := logrus.New()
hook := NewHook("my-secret-token", "production")
log.Hooks.Add(hook)

// This will not be reported to Rollbar
log.WithFields(logrus.Fields{"power_level": "9001"}).Debug("It's over 9000!")

// This will be reported to Rollbar
log.Panic("Boom.")

func NewHookForLevels Uses

func NewHookForLevels(token string, env string, levels []logrus.Level) *Hook

NewHookForLevels provided by the caller. Otherwise works like NewHook.

func (*Hook) Fire Uses

func (r *Hook) Fire(entry *logrus.Entry) error

Fire the hook. This is called by Logrus for entries that match the levels returned by Levels().

func (*Hook) Levels Uses

func (r *Hook) Levels() []logrus.Level

Levels returns the logrus log.Levels that this hook handles

type OptionFunc Uses

type OptionFunc func(*Hook)

OptionFunc that can be passed to NewHook.

func WithIgnoreErrorFunc Uses

func WithIgnoreErrorFunc(fn func(error) bool) OptionFunc

WithIgnoreErrorFunc is an OptionFunc that receives the error that is about to be logged and returns true/false if it wants to fire a Rollbar alert for.

func WithIgnoreFunc Uses

func WithIgnoreFunc(fn func(err error, fields map[string]interface{}) bool) OptionFunc

WithIgnoreFunc is an OptionFunc that receives the error and custom fields that are about to be logged and returns true/false if it wants to fire a Rollbar alert for.

func WithIgnoredErrors Uses

func WithIgnoredErrors(errors ...error) OptionFunc

WithIgnoredErrors is an OptionFunc that whitelists certain errors to prevent them from firing. See https://golang.org/ref/spec#Comparison_operators

func WithLevels Uses

func WithLevels(levels ...logrus.Level) OptionFunc

WithLevels is an OptionFunc that customizes the log.Levels the hook will report on.

func WithMinLevel Uses

func WithMinLevel(level logrus.Level) OptionFunc

WithMinLevel is an OptionFunc that customizes the log.Levels the hook will report on by selecting all levels more severe than the one provided.

Package rollrus imports 6 packages (graph) and is imported by 2 packages. Updated 2019-09-30. Refresh now. Tools for package owners.