---
title: Node.js agent logs in context
source: https://docs.newrelic.com/docs/logs/logs-context/configure-logs-context-nodejs
---

With our Node.js APM agent, you can get APM logs in context, which lets you see your app logs in the context of your other New Relic data. For general information on this feature, see [APM logs in context](https://docs.newrelic.com/docs/apm/new-relic-apm/getting-started/get-started-logs-context).

> #### 💡 TIP
>
> Got lots of Node.js logs? Check out our [tutorial on how to optimize and manage them](https://docs.newrelic.com/docs/tutorial-large-logs/get-started-managing-large-logs/).

## Automatic logs in context options [#automatic]

With application logging, your APM agent automatically collects and contextualizes your logs.

If you're using a supported framework, you have three options to configure APM logs in context to send your app's logs and linking metadata automatically to New Relic.

Supported frameworks for automatic logs in context include:

-   [Winston](https://github.com/winstonjs/winston) 3.0.0 or higher.
-   [Pino](https://github.com/pinojs/pino) 7.0.0 or higher.
-   [Bunyan](https://www.npmjs.com/package/bunyan) 1.8.12 or higher (since agent version 9.3.0)

If you're not using a supported framework, you may instead use the agent's log forwarding API method to perform your own instrumentation. For details, see the [Node.js agent API docs](https://newrelic.github.io/node-newrelic/API.html#recordLogEvent).

> #### ⚠️ IMPORTANT
>
> Agent releases 8.16.0 and higher have this feature enabled in the agent configuration file by default.
>
> Agent log forwarding will cause an increase in the consumption of data when a [supported framework](https://docs.newrelic.com/docs/logs/logs-context/node-configure-logs-context-all#automatic) is detected. The amount depends on the application and amount of logs it produces. This feature can be disabled. See [Disable automatic logging](https://docs.newrelic.com/docs/logs/logs-context/disable-automatic-logging/) for more information about your options.
>
> If you already have a log forwarding solution in place, you should disable this feature.

**Option 1 (simplest): Let the agent decorate and forward your logs.**

This is the simplest approach, and it's a great choice for developers who may not have the access or interest in setting up a log forwarder, or for accounts that want to see the power of logs and other linking metadata in context of their apps, without a lot of overhead.

Using this option, the agent reports your entire log and adds our attributes `span.id`, `trace.id`, `hostname`, `entity.guid`, and `entity.name`. These attributes link your logs to spans, traces, and other telemetry, making it easier to troubleshoot.

All you need to do is install an agent version with log forwarding capabilities ([Node.js agent 8.11.0 or higher](https://docs.newrelic.com/docs/release-notes/agent-release-notes/nodejs-release-notes/)). If forwarding is disabled, you can use this configuration:

newrelic.js:

````js
application_logging: {
  forwarding: {
    enabled: true
  }
}
```

Environment variable:

```
NEW_RELIC_APPLICATION_LOGGING_FORWARDING_ENABLED=true
```

This option is on by default since agent version 8.16.0.

<DNT>
  **Optional adjustments:**
</DNT>

Once this is enabled, you also have control over the maximum number of logs sent to New Relic every minute. The default value is 10,000. If more than 10,000 logs are received in a 60-second window, your logs will begin to be sampled.

Set it to a higher number to receive more logs. Set it to a lower number to receive fewer logs. Any integer up to 100,000 is valid. Increasing this value may increase the agent's utilization of CPU and RAM.

newrelic.js:

```js
application_logging: {
  forwarding: {
    max_samples_stored: 10000
  }
}
```

Environment variable:

```
NEW_RELIC_APPLICATION_LOGGING_FORWARDING_MAX_SAMPLES_STORED: 10000
```

If you have an existing log forwarding solution and are updating your agent to use automatic logs in context, be sure to <DNT>**disable your manual log forwarder**</DNT>. Otherwise, your app will be sending double log lines. Depending on your account, this could result in double billing. For more information, follow the procedures to disable your [specific log forwarder](/docs/logs/forward-logs/enable-log-management-new-relic#log-forwarding).

````

**Option 2: Let the agent decorate your logs.**

Already have a log forwarder you like? We've got you covered! Language agents can decorate your logs with the linking metadata needed to provide access to automatic logs-in-context features.

This option should not be used with in-agent forwarding. Using an [external log forwarder](https://docs.newrelic.com/docs/logs/forward-logs/enable-log-management-new-relic#log-forwarding) to send logs to New Relic while in-agent forwarding is enabled will cause your logs to be sent up twice to New Relic. Depending on your account, this may result in double billing.

1.  If you want to use this option, make sure you have the in-agent forwarding configuration option disabled.

    newrelic.js:

    ```js
    application_logging: {
      forwarding: {
        enabled: false
      }
    }
    ```

2.  Enable log decorating in your configuration, then relaunch the agent to start decorating your logs.

    newrelic.js:

    ```js
    application_logging: {
      local_decorating: {
        enabled: true
      }
    }
    ```

    Environment variable:

    ```
    NEW_RELIC_APPLICATION_LOGGING_LOCAL_DECORATING_ENABLED=true
    ```

    Our decorator adds five attributes to every log message: `entity.guid`, `entity.name`, `hostname`, `trace.id`, and  `span.id`. Example:

    ```
    This is my log message. NR-LINKING|{entity.guid}|{hostname}|{trace.id}|{span.id}|{entity.name}|
    ```

    If the log message is empty or blank, output message will also be empty. Example:

    ```
     NR-LINKING|{entity.guid}|{hostname}|{trace.id}|{span.id}|{entity.name}|.
    ```

    The output log message will be an empty string.

    Some attributes may be empty if the log occurred outside a transaction or if they are not applicable to your application's context.

## Secure your data [#obfuscation]

Your logs may include sensitive information protected by HIPAA or other compliance protocols. By default we obfuscate number patterns that appear to be for items such as credit cards or Social Security numbers, but you may need to hash or mask additional information.

For more information, see our documentation about [obfuscation expressions and rules](https://docs.newrelic.com/docs/logs/ui-data/obfuscation-ui/). You can hash or mask your log data by using the New Relic UI or by using NerdGraph, our GraphQL API.

## Explore your data [#view-ui]

To make the most of your logging data:

-   On the [APM **Summary** page](https://docs.newrelic.com/docs/apm/apm-ui-pages/monitoring/apm-summary-page-view-transaction-apdex-usage-data), click your **Web transaction time** chart to view logs associated with a specific point in time.
-   Check your app's [**Errors inbox**](https://docs.newrelic.com/docs/errors-inbox/errors-inbox) to view the logs associated with your errors.
-   Use [distributed tracing](https://docs.newrelic.com/docs/distributed-tracing/ui-data/understand-use-distributed-tracing-ui) to see the logs associated with individual traces.
-   Explore more logging data across your platform with our [logs UI](https://docs.newrelic.com/docs/logs/log-management/ui-data/use-logs-ui/).
-   Set up [alerts](https://docs.newrelic.com/docs/alerts-applied-intelligence/new-relic-alerts/alert-conditions/create-alert-conditions/) based on log output and severity.
-   [Query your data](https://docs.newrelic.com/docs/logs/ui-data/query-syntax-logs/) using our specialized UI for logs data, and [create dashboards](https://docs.newrelic.com/docs/query-your-data/explore-query-data/dashboards/introduction-dashboards/) with the results.

## Troubleshooting tips [#troubleshooting]

Typically your logs will start to appear less than a minute after you enable APM logs in context. Check your app's **Triage > Logs** section. You will also start seeing [log patterns](https://docs.newrelic.com/docs/logs/ui-data/find-unusual-logs-log-patterns) related to the error there.

If you don't see any logs for errors or traces, there may not be any for your app. Try refreshing the UI page, or change the [selected time period](https://docs.newrelic.com/docs/new-relic-one/ui-data/basic-ui-features/#data-analysis).

## Disable automatic logging [#disable-automatic]

APM logs in context automatically forwards APM agent log data. It is enabled by default. If you do enable application logging, it can have a negative impact on your security, compliance, billing, or system performance. For more information, or if you need to adjust the default setting, follow the procedures to [disable automatic logging](https://docs.newrelic.com/docs/logs/logs-context/disable-automatic-logging).

## What's next? [#what-next]

After you set up APM logs in context, make the most of your logging data:

-   Explore the logging data across your platform with our [logs UI](https://docs.newrelic.com/docs/logs/log-management/ui-data/use-logs-ui/).
-   See your logs in context of your app's performance in the [APM UI](https://docs.newrelic.com/docs/logs/log-management/ui-data/use-logs-ui/#links). Troubleshoot [errors](https://docs.newrelic.com/docs/apm/apm-ui-pages/error-analytics/errors-page-find-fix-verify-problems/) with [distributed tracing](https://docs.newrelic.com/docs/apm/distributed-tracing/ui-data/understand-use-distributed-tracing-data), stack traces, application logs, and more.
-   Get deeper visibility into both your application and your platform performance data by forwarding your logs with our [infrastructure agent](https://docs.newrelic.com/docs/logs/enable-log-management-new-relic/enable-log-monitoring-new-relic/forward-your-logs-using-infrastructure-agent/). Review your [infrastructure logs](https://docs.newrelic.com/docs/logs/log-management/ui-data/use-logs-ui/#links) in the UI.
-   Set up [alerts](https://docs.newrelic.com/docs/alerts-applied-intelligence/new-relic-alerts/alert-conditions/create-alert-conditions/).
-   [Query your data](https://docs.newrelic.com/docs/query-your-data/explore-query-data/get-started/introduction-querying-new-relic-data/) and [create dashboards](https://docs.newrelic.com/docs/query-your-data/explore-query-data/dashboards/introduction-dashboards/).
