logWriter

package module
Version: v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2022 License: Apache-2.0 Imports: 5 Imported by: 0

README

New Relic Log Writer

The logWriter library is an io.Writer that automatically integrates the latest New Relic Logs in Context features into the go standard library logger. When used as the io.Writer for log, 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 log.

Usage

Once your New Relic application has been created, create a logWriter 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 := logWriter.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 logWriter 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 LogWriter

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

func New

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

New creates a new LogWriter 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 (*LogWriter) DebugLogging

func (lw *LogWriter) 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 (*LogWriter) WithContext

func (lw *LogWriter) WithContext(ctx context.Context) LogWriter

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

func (*LogWriter) WithTransaction

func (lw *LogWriter) WithTransaction(txn *newrelic.Transaction) LogWriter

WithTransaction creates a new LogWriter for a specific transactions

func (LogWriter) Write

func (lw LogWriter) 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

Source Files

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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