Skip to content

Instantly share code, notes, and snippets.

@AlecIsaacson
Last active February 12, 2020 18:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AlecIsaacson/f139d5529b9a0af5c3f32ccdf0802877 to your computer and use it in GitHub Desktop.
Save AlecIsaacson/f139d5529b9a0af5c3f32ccdf0802877 to your computer and use it in GitHub Desktop.
Sample log4j2.xml that adds the lines needed to enable New Relic Logs in Context for Log4J v2.x.
<!--
This is a full example showing the one line you need to add to log4j2.xml to enable New Relic Logs in Context.
Most of this file is stock - the only changes needed are shown below, flagged with comments.
-->
<?xml version="1.0" encoding="UTF-8"?>
<Configuration xmlns="http://logging.apache.org/log4j/2.0/config"
status="WARN"
<!-- New Relic Logs in Context - Add NR Log4J extension -->
packages="com.newrelic.logging.log4j2">
<Appenders>
<Console name="STDOUT" target="SYSTEM_OUT">
<!-- New Relic Logs in Context - Enable the NR layout -->
<NewRelicLayout/>
<JsonLayout compact="true" eventEol="true">
<KeyValuePair key="logging.googleapis.com/trace" value="$${ctx:traceId}"/>
<KeyValuePair key="logging.googleapis.com/spanId" value="$${ctx:spanId}"/>
<KeyValuePair key="logging.googleapis.com/traceSampled" value="$${ctx:traceSampled}"/>
<KeyValuePair key="time" value="$${date:yyyy-MM-dd}T$${date:HH:mm:ss.SSS}Z"/>
</JsonLayout>
</Console>
</Appenders>
<Loggers>
<Logger name="io.grpc.netty" level="INFO"/>
<Logger name="io.netty" level="INFO"/>
<Logger name="sun.net" level="INFO"/>
<Root level="TRACE">
<AppenderRef ref="STDOUT"/>
</Root>
</Loggers>
</Configuration>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment