• /
  • Log in
  • Free account

Java: Configure with java.util.logging

New Relic offers a java.util.logging extension for log management, allowing you link to your log data with related data across the rest of the New Relic platform. This document explains how to configure logs in context and start getting log data. The code and an example application are available on GitHub.

Compatibility and requirements

To use New Relic logs in context with java.util.logging, ensure your configuration meets the following requirements:

Configure logs in context with log management

To configure New Relic logs in context with java-util-logging:

  1. Enable log management with a compatible log forwarding plugin.
  2. Install or update the Java agent.
  3. Configure the java.util.logging extension.
  4. Check for logging data.

Enable log management

Confirm that you have log management enabled, with a compatible log forwarding plugin installed to send your application logs to New Relic.

Install or update the Java agent

Install or update to the most recent Java agent version, and enable Distributed tracing.

Configure the java.util.logging extension

To configure logs in context with the java.util.logging extension, complete the following steps:

  1. Update your project's dependencies to include the java.util.logging extension as applicable:

    • To update with Gradle, add the following to your build.gradle file:

      dependencies {
    • To update with Maven, add the following to your pom.xml file:



      Can't edit these files? You can add the jars directly to the application classpath.

  2. Use the NewRelicMemoryHandler to intercept messages destined for another handler. Your file will have a handlers property, but it might be set to something else. Your logging properties file will include a line listing the root logger's handlers, like this:

    handlers = java.util.logging.FileHandler
  3. Update your logging properties file set the root logger's handler.

    handlers = com.newrelic.logging.jul.NewRelicMemoryHandler
  4. Configure the NewRelicMemoryHandler by setting the target to the handler that was previously set for the handlers property. The value of this property should be the handler that was previously assigned to the root logger.

    com.newrelic.logging.jul.NewRelicMemoryHandler.target = java.util.logging.FileHandler


    Why? The New Relic log format includes data from the New Relic agent that must be captured on the thread the log message is coming from. This MemoryHandler implementation intercepts that data.

  5. Use a NewRelicFormatter for the final handler.

    Update your logging properties file to set the formatter property like the example below. Note: the handler on which you set the formatter must be the target handler from the previous step (java.util.logging.FileHandler in this example).

    java.util.logging.FileHandler.formatter = com.newrelic.logging.jul.NewRelicFormatter


    Why? The New Relic log format is a tailored JSON format with specific fields in specific places that our log forwarder plugins and back end rely on. At this time, we don't support any customization of that format.


    Once complete, JSON is logged instead of text. The JSON should be formatted as single objects, one per line, and should contain fields likelog.level and thread.name. The trace.id, which is required for Logs in Context,should only have a value for log messages that occur within a transaction.

Check for logging data

To verify that you have configured the extension correctly, run your application and verify that the logging you have configured contains the following:

  • Includes trace.id and span.id fields
  • Is properly-formatted JSON lines

If everything is configured correctly and your data is being reported, you should see data logs in the New Relic Logs UI using the query operator has: span.id/trace.id.

What's next?

Now that you've set up APM logs in context, here are some potential next steps:

For more help

If you need more help, check out these support and learning resources:

Create issueEdit page
Copyright © 2021 New Relic Inc.