zerologWriter

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2022 License: Apache-2.0 Imports: 9 Imported by: 6

README

New Relic Zerolog Writer

The zerolog-writer library is an io.Writer that automatically integrates the latest New Relic Logs in Context features into Zerolog. When used as the io.Writer for zerolog, this tool will collect log metrics, forward logs, and enrich logs depending on how your New Relic application is configured. This is the most complete and convenient way to to capture log data with New Relic in Zerolog.

Usage

Once your New Relic application has been created, create a ZerologWriter instance. It must be passed an io.Writer, which is where the final log content will be written to, and a pointer to New Relic application.

writer := zerologWriter.New(os.Stdout, app)

If any errors occor while trying to decorate your log with New Relic metadata, it will fail silently and print your log message in its original, unedited form. If you want to see the error messages, then enable debug logging. This will print an error message in a new line after the original log message is printed.

writer.DebugLogging(true)

To capture log data in the context of a transaction, make a new ZerologWriter with the WithTransaction or WithContext methods.

If you have a pointer to a transaction, use the WithTransaction() function.

txn := app.StartTransaction("my transaction")
defer txn.End()
txnWriter := writer.WithTransaction(txn)

If you have a context with a transaction pointer in it, use the WithContext() function.

func ExampleHandler(w http.ResponseWriter, r *http.Request) {
    txnWriter := writer.WithContext(r.Context())
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ZerologWriter

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

func New

func New(output io.Writer, app *newrelic.Application) ZerologWriter

New creates a new NewRelicWriter Object output is the io.Writer destination that you want your log to be written to app must be a vaild, non nil new relic Application

func (*ZerologWriter) DebugLogging

func (zw *ZerologWriter) DebugLogging(enabled bool)

DebugLogging toggles whether error information should be printed to console. By default, this service will fail silently. Enabling debug logging will print error messages on a new line after your log message.

func (*ZerologWriter) WithContext

func (zw *ZerologWriter) WithContext(ctx context.Context) ZerologWriter

WithContext creates a new ZerologWriter for the transaction inside of a context

func (*ZerologWriter) WithTransaction

func (zw *ZerologWriter) WithTransaction(txn *newrelic.Transaction) ZerologWriter

WithTransaction creates a new ZerologWriter for a specific transactions

func (ZerologWriter) Write

func (zw ZerologWriter) Write(p []byte) (n int, err error)

Write is a valid io.Writer method that will write the content of an enriched log to the output io.Writer

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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