Skip to content

Instantly share code, notes, and snippets.

@AlecIsaacson

AlecIsaacson/log4j2.xml

Last active Feb 12, 2020
Embed
What would you like to do?
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
You can’t perform that action at this time.