• /
  • EnglishEspañolFrançais日本語한국어Português
  • 로그인지금 시작하기

Go agent logging

New Relic for Go logging uses the standard Go log package and a New Relic Logger package. Logging is useful for troubleshooting your New Relic integration; for example, with installation or configuration problems.

Write log files

To use the Go agent methods for writing log and audit files, see log.go on the agent GitHub repo.

Logrus integrations

New Relic offers two Logrus integrations for different use cases:

Agent logging (for Go agent debug messages)

Use this integration to send the Go agent's internal log messages to Logrus. This is useful for troubleshooting the agent itself.

Integration: nrlogrus

Here is an example of using the New Relic Logrus integration for agent logging:

  1. Import the required packages:

    import (
    "os"
    "github.com/newrelic/go-agent/v3/integrations/nrlogrus"
    "github.com/newrelic/go-agent/v3/newrelic"
    "github.com/sirupsen/logrus"
    )
  2. Configure the Go agent to use Logrus for agent logging:

    app, err := newrelic.NewApplication(
    newrelic.ConfigAppName("Your Application Name"),
    newrelic.ConfigLicense(os.Getenv("NEW_RELIC_LICENSE_KEY")),
    func(config *newrelic.Config) {
    logrus.SetLevel(logrus.DebugLevel)
    config.Logger = nrlogrus.StandardLogger()
    },
    )

Application logs (logs in context)

Use this integration to send your application's Logrus log messages to New Relic with automatic trace correlation. This enables logs in context, allowing you to see log messages related to your errors and traces directly in your app's UI.

Integration: logcontext-v2/nrlogrus

Here is an example of using the New Relic Logrus integration for application logging:

  1. Import the required packages:

    import (
    "context"
    "os"
    "github.com/newrelic/go-agent/v3/integrations/logcontext-v2/nrlogrus"
    "github.com/newrelic/go-agent/v3/newrelic"
    "github.com/sirupsen/logrus"
    )
  2. Configure Logrus to use the New Relic formatter:

    app, err := newrelic.NewApplication(
    newrelic.ConfigAppName("Your Application Name"),
    newrelic.ConfigLicense(os.Getenv("NEW_RELIC_LICENSE_KEY")),
    newrelic.ConfigAppLogForwardingEnabled(true),
    )
    logger := logrus.New()
    logger.SetFormatter(nrlogrus.NewFormatter(app, &logrus.TextFormatter{}))
  3. Use the logger in your application with transaction context:

    txn := app.StartTransaction("myTransaction")
    defer txn.End()
    ctx := newrelic.NewContext(context.Background(), txn)
    logger.WithContext(ctx).Info("This log will be correlated with the transaction")

For more examples, see the logcontext-v2/nrlogrus examples.

Other supported logging integrations

In addition to Logrus, New Relic provides integrations for several other popular Go logging libraries:

Agent logging integrations

These integrations send the Go agent's internal debug messages to your logging framework:

  • nrzap - Integration with Uber's Zap logger
  • nrslog - Integration with Go's standard library log/slog package
  • nrzerolog - Integration with Zerolog
  • nrlogxi - Integration with Logxi

Logs in context integrations

These integrations enable logs in context for your application logs:

Each integration follows a similar pattern to the Logrus examples above. See the respective GitHub repositories for detailed usage instructions and examples.

View logs for your APM and infrastructure data

With logs in context, you can see log messages related to your errors and traces directly in your app's UI. You can also see logs in context of your infrastructure data, such as Kubernetes clusters. No need to switch to another UI page.

To enable logs in context, use one of the logs in context integrations listed above. For Logrus specifically, see the logcontext-v2/nrlogrus integration.

Copyright © 2026 New Relic Inc.

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.