• English日本語한국어
  • Log inStart now

Java agent logs in context

With our Java agent, you can get 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.

Tip

Got lots of Java logs? Check out our tutorial on how to optimize and manage them.

Automatic logs in context options

If you are using a supported framework, you have two options to configure APM logs in context to send your app's logs and linking metadata automatically to New Relic. One option is to manually configure a log extension that will decorate your logs and then you can forward them to yourself. The other option is to have the Java agent automatically handle decorating and forwarding of your logs. Supported frameworks for automatic logs in context include:

  • Log4j1 1.2.17 or higher
  • Log4j2 2.6 or higher
  • Logback 1.1 or higher
  • JUL (java.util.logging) JDK 8+
  • JBoss Logging 1.3.0.Final to 2.x
  • Dropwizard Logging (captured via Logback instrumentation, see know issue below)

Important

JBoss Logging

JBoss Logging delegates the local decorating functionality to the JUL instrumentation and thus can be completely comtrolled by the following two instrumentation modules:

class_transformer:
com.newrelic.instrumentation.java.logging-jdk8:
enabled: true
com.newrelic.instrumentation.jboss.logging:
enabled: true

Important

Known Issue With Dropwizard Logging

By default, Dropwizard uses Logback for its logging backend. It also routes all java.util.logging, Log4j, and Apache Commons Logging usage through Logback. This routing behavior can lead to duplicate logs being reported to New Relic if the Java agent instruments one of these other logging libraries in addition to instrumenting Logback.

To avoid reporting duplicate logs when using Dropwizard logging, it is recommended that you disable all of the logging framework instrumentation except for Logback. You can do this in the class_transformer section in the agent configuration file:

class_transformer:
com.newrelic.instrumentation.logback-classic-1.2:
enabled: true
com.newrelic.instrumentation.apache-log4j-1:
enabled: false
com.newrelic.instrumentation.apache-log4j-2:
enabled: false
com.newrelic.instrumentation.java.logging-jdk8:
enabled: false
com.newrelic.instrumentation.jboss.logging:
enabled: false

Important

Agent releases 7.7.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 is detected. The amount depends on the application and amount of logs it produces. This feature can be disabled. See Disable automatic logging for more information about your options.

If you already have a log forwarding solution in place, you should disable this feature.

If you prefer to use your own log forwarder, rather than having the Java agent forward logs, then our manual logs in context solution would be the right solution for decorating your logs with trace context metadata.

Did this doc help with your installation?

Secure your data

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. You can hash or mask your log data by using the New Relic UI or by using NerdGraph, our GraphQL API.

Explore your data

To make the most of your logging data:

  • On the APM Summary page, click your Web transaction time chart to view logs associated with a specific point in time.
  • Check your app's Errors inbox to view the logs associated with your errors.
  • Use distributed tracing to see the logs associated with individual traces.
  • Explore more logging data across your platform with our logs UI.
  • Set up alerts based on log output and severity.
  • Query your data using our specialized UI for logs data, and create dashboards with the results.

Troubleshooting tips

Typically your logs will start to appear less than a minute after you enable logs in context. Check your app's Triage > Logs section. You will also start seeing 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.

Disable automatic logging

APM logs in context automatically forwards agent log data and is enabled by default. This can have a negative impact on your security, compliance, billing, or system performance. To disable automatic logs:

  1. From the user menu in the New Relic UI, click Manage your data > Log settings.
  2. Click the ellipsis ... menu at the right side of the account's row.
  3. Click the confirmation button to enable or disable and lock or unlock automatic logging (parent accounts) or enable or disable only (child accounts).

For more information, or if you need to adjust the default setting, follow the procedures to disable automatic logging.

Manual logs in context option

Before language agents had the ability to forward and decorate logs, you could use our manual solutions to send linking metadata.

This option is still supported, but is no longer encouraged. Also, this method requires that you install a log forwarder before enabling logs in context. If you do not have a log forwarder, the New Relic UI will prompt you to use our infrastructure agent.

If you decide to use your existing log forwarding solution and later decide to update your agent to use automatic logs in context, be sure to disable your manual log forwarder. 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.

If you need to use the manual process to set up logs in context for Java, follow these steps:

  1. Make sure you have already set up logging in New Relic. This includes configuring a supported log forwarder that collects your application logs and extends the metadata that is forwarded to New Relic.
  2. Install or update to the latest Java agent version. Use Java agent version 5.6.0 or higher for logs in context.
  3. Enable the JVM argument -javaagent, and enable distributed tracing.
  4. Configure logs in context for Java to enrich your log data, using any of the following extensions as applicable. If you use Spring or Spring Boot and aren't sure which extension you need, see our Spring documentation.
Copyright © 2024 New Relic Inc.

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