nrlogrus

package module
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: May 9, 2023 License: Apache-2.0 Imports: 5 Imported by: 1

README

nrlogrus

Go Reference Go Report Card Maintainability Test Coverage

NewRelic hook for Logrus, with logcontext support.

Why

Official hooks are not covering cases when NewRelic client is not yet created, or failed, but we still want logs for this entity to be connected to the APM. Turns out for this we need to only send the entity.name and entity.type.

Install

go get github.com/brokeyourbike/nrlogrus

Use

You can pass the application name to the function:

log.SetFormatter(nrlogrus.NewFormatter("my-app", &logrus.JSONFormatter{}))

or read it from environment variable NEW_RELIC_APP_NAME:

log.SetFormatter(nrlogrus.NewFormatterFromEnvironment(&logrus.JSONFormatter{}))

Thanks

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ContextFormatter

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

ContextFormatter is a `logrus.Formatter` that will format logs for sending to New Relic.

func NewFormatter

func NewFormatter(appName string, formatter logrus.Formatter) ContextFormatter

NewFormatter creates a new `logrus.Formatter` that will format logs for sending to New Relic.

func NewFormatterFromEnvironment

func NewFormatterFromEnvironment(formatter logrus.Formatter) ContextFormatter

NewFormatterFromEnvironment creates a new `logrus.Formatter` that will format logs for sending to New Relic. The application name is read from the `NEW_RELIC_APP_NAME` environment variable.

func (ContextFormatter) Format

func (f ContextFormatter) Format(e *logrus.Entry) ([]byte, error)

Format renders a single log entry.

Jump to

Keyboard shortcuts

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