nrslog

package module
v1.5.2 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2025 License: Apache-2.0 Imports: 8 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrAlreadyWrapped = errors.New("handler is already wrapped with a New Relic handler")
View Source
var ErrNilApp = errors.New("New Relic application cannot be nil")
View Source
var ErrNilHandler = errors.New("slog handler cannot be nil")

Functions

func JSONHandler deprecated

func JSONHandler(app *newrelic.Application, w io.Writer, opts *slog.HandlerOptions) slog.Handler

JSONHandler creates a wrapped Slog JSONHandler, enabling it to both automatically capture logs and to enrich logs locally depending on your logs in context configuration in your New Relic application.

Deprecated: Use WrapHandler() instead.

func New

func New(app *newrelic.Application, handler slog.Handler) *slog.Logger

New Returns a new slog.Logger object wrapped with a New Relic handler that controls logs in context features.

func TextHandler deprecated

func TextHandler(app *newrelic.Application, w io.Writer, opts *slog.HandlerOptions) slog.Handler

TextHandler creates a wrapped Slog TextHandler, enabling it to both automatically capture logs and to enrich logs locally depending on your logs in context configuration in your New Relic application.

Deprecated: Use WrapHandler() instead.

func WithContext

func WithContext(ctx context.Context, logger *slog.Logger) *slog.Logger

WithTransaction creates a new Slog Logger object to be used for logging within a given transaction it its found in a context. Creating a transaction logger can have a performance benefit when transactions are long running, and have a high log volume in comparison to reading transactions from context on every log message.

Note: transaction contexts can also be passed to the logger without creating a new logger using logger.InfoContext() or similar commands.

func WithTransaction

func WithTransaction(txn *newrelic.Transaction, logger *slog.Logger) *slog.Logger

WithTransaction creates a new Slog Logger object to be used for logging within a given transaction. Creating a transaction logger can have a performance benefit when transactions are long running, and have a high log volume in comparison to reading transactions from context on every log message.

Note: transaction contexts can also be passed to the logger without creating a new logger using logger.InfoContext() or similar commands.

func WithTransactionFromContext deprecated

func WithTransactionFromContext(handler slog.Handler) slog.Handler

WithTransactionFromContext creates a wrapped NRHandler, enabling it to automatically reference New Relic transaction from context.

Deprecated: this is a no-op

func WrapHandler

func WrapHandler(app *newrelic.Application, handler slog.Handler) slog.Handler

WrapHandler returns a new handler that is wrapped with New Relic tools to capture log data based on your application's logs in context settings.

Note: This function will silently error, and always return a valid handler to avoid service disruptions. If you would prefer to handle errors when wrapping your handler, use the Wrap() function instead.

Types

type NRHandler

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

NRHandler is an Slog handler that includes logic to implement New Relic Logs in Context. Please always create a new handler using the Wrap() or WrapHandler() functions to ensure proper initialization.

Note: shallow coppies of this handler may not duplicate underlying datastructures, and may cause logical errors. Please use the Clone() method to create deep coppies, or use the WithTransaction, WithAttrs, or WithGroup methods to create new handlers with additional data.

func Wrap

func Wrap(app *newrelic.Application, handler slog.Handler) (*NRHandler, error)

WrapHandler returns a new handler that is wrapped with New Relic tools to capture log data based on your application's logs in context settings.

func (*NRHandler) Clone

func (h *NRHandler) Clone() *NRHandler

Clone creates a deep copy of the original handler, including a copy of all cached data and the underlying handler.

Note: application, transaction, and handler pointers will be coppied, but the underlying data will not be duplicated.

func (*NRHandler) Enabled

func (h *NRHandler) Enabled(ctx context.Context, lvl slog.Level) bool

Enabled reports whether the handler handles records at the given level. The handler ignores records whose level is lower.

func (*NRHandler) Handle

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

Handle handles the Record. It will only be called when Enabled returns true.

func (*NRHandler) WithAttrs

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

WithAttrs returns a new Handler whose attributes consist of both the receiver's attributes and the arguments.

This wraps the WithAttrs of the underlying handler, and will not modify the attributes slice in any way.

func (*NRHandler) WithGroup

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

WithGroup returns a new Handler with the given group appended to the receiver's existing groups. The keys of all subsequent attributes, whether added by With or in a Record, should be qualified by the sequence of group names. If the name is empty, WithGroup returns the receiver.

func (*NRHandler) WithTransaction

func (h *NRHandler) WithTransaction(txn *newrelic.Transaction) *NRHandler

WithTransaction returns a new handler that is configured to capture log data and attribute it to a specific transaction.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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