---
title: Go agent logging
source: https://docs.newrelic.com/docs/apm/agents/go-agent/configuration/go-agent-logging
---

[New Relic for Go](https://docs.newrelic.com/docs/agents/go-agent/get-started/new-relic-go) logging uses the standard [Go log package](https://golang.org/pkg/log/) and a New Relic `Logger` package. Logging is useful for [troubleshooting](https://docs.newrelic.com/docs/agents/go-agent/troubleshooting/no-data-appears-go) your New Relic integration; for example, with [installation](https://docs.newrelic.com/docs/agents/go-agent/get-started/install-new-relic-go) or [configuration](https://docs.newrelic.com/docs/agents/go-agent/instrumentation/go-agent-configuration) problems.

## Write log files [#write-logfiles]

To use the Go agent methods for writing log and audit files, see [log.go on the agent GitHub repo](https://github.com/newrelic/go-agent/blob/20541a9393ae651949eb75b82666d4a7c2a10dec/v3/newrelic/log.go).

## Logrus integrations [#logrus]

New Relic offers two Logrus integrations for different use cases:

### Agent logging (for Go agent debug messages) [#agent-logging]

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

**Integration:** [`nrlogrus`](https://github.com/newrelic/go-agent/tree/master/v3/integrations/nrlogrus)

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

1.  Import the required packages:

    ```go
    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:

    ```go
    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) [#application-logging]

Use this integration to send your application's Logrus log messages to New Relic with automatic trace correlation. This enables [logs in context](https://docs.newrelic.com/docs/logs/logs-context/configure-logs-context-go/), allowing you to see log messages related to your errors and traces directly in your app's UI.

**Integration:** [`logcontext-v2/nrlogrus`](https://github.com/newrelic/go-agent/tree/master/v3/integrations/logcontext-v2/nrlogrus)

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

1.  Import the required packages:

    ```go
    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:

    ```go
    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:

    ```go
    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](https://github.com/newrelic/go-agent/tree/master/v3/integrations/logcontext-v2/nrlogrus/example).

## Other supported logging integrations [#other-integrations]

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

### Agent logging integrations [#other-agent-logging]

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

-   **[nrzap](https://github.com/newrelic/go-agent/tree/master/v3/integrations/nrzap)** - Integration with Uber's Zap logger
-   **[nrslog](https://github.com/newrelic/go-agent/tree/master/v3/integrations/nrslog)** - Integration with Go's standard library `log/slog` package
-   **[nrzerolog](https://github.com/newrelic/go-agent/tree/master/v3/integrations/nrzerolog)** - Integration with Zerolog
-   **[nrlogxi](https://github.com/newrelic/go-agent/tree/master/v3/integrations/nrlogxi)** - Integration with Logxi

### Logs in context integrations [#other-logs-context]

These integrations enable logs in context for your application logs:

-   **[logcontext-v2/zerologWriter](https://github.com/newrelic/go-agent/tree/master/v3/integrations/logcontext-v2/zerologWriter)** - Send Zerolog log messages to New Relic with trace correlation
-   **[logcontext-v2/logWriter](https://github.com/newrelic/go-agent/tree/master/v3/integrations/logcontext-v2/logWriter)** - Send standard library `log` package messages to New Relic with trace correlation

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 [#logs-context]

With [logs in context](https://docs.newrelic.com/docs/logs/logs-context/configure-logs-context-go/), 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](https://docs.newrelic.com/docs/logs/forward-logs/forward-your-logs-using-infrastructure-agent/), 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](#other-logs-context) listed above. For Logrus specifically, see the [`logcontext-v2/nrlogrus`](#application-logging) integration.
