rollrus

package module
v0.0.0-...-59371b8 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2018 License: MIT Imports: 10 Imported by: 0

README

Build Status GoDoc

What

Rollrus is what happens when Logrus meets Roll.

When a .Error, .Fatal or .Panic logging function is called, report the details to rollbar via a Logrus hook.

Delivery is synchronous to help ensure that logs are delivered.

If the error includes a StackTrace, that StackTrace is reported to rollbar.

Usage

Examples available in the tests or on GoDoc.

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func ReportPanic

func ReportPanic(token, env string)

ReportPanic attempts to report the panic to rollbar if the token is set

func SetupLogging

func SetupLogging(token, env string) io.Closer

SetupLogging sets up logging. 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, which is suitable for use on Heroku.

Example
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.")
Output:

func SetupLoggingForLevels

func SetupLoggingForLevels(token, env string, config RollrusConfig) io.Closer

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

Types

type Hook

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

Hook wrapper for the rollbar Client May be used as a rollbar client itself

func NewHook

func NewHook(token string, env string) *Hook

Setup a new hook with default reporting levels, useful for adding to your own logger instance.

Example
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.")
Output:

func NewHookForLevels

func NewHookForLevels(token string, env string, config RollrusConfig) *Hook

Setup a new hook with specified reporting levels, useful for adding to your own logger instance.

func (*Hook) Close

func (r *Hook) Close() error

func (*Hook) Fire

func (r *Hook) Fire(entry *log.Entry) (err error)

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

func (*Hook) Levels

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

Levels returns the logrus log levels that this hook handles

func (*Hook) ReportPanic

func (r *Hook) ReportPanic()

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.

type RollrusConfig

type RollrusConfig struct {
	Buffer     buffer.Buffer
	NumWorkers int
	LogLevels  []log.Level
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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