0% found this document useful (0 votes)
36 views4 pages

Log4j2 Configurations

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views4 pages

Log4j2 Configurations

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 4

Exception in thread "main" java.lang.

IllegalArgumentException:
LoggerFactory is not a Logback LoggerContext but Logback is on
the classpath. Either remove Logback or the competing
implementation (class org.apache.logging.slf4j.Log4jLoggerFactory
loaded from
file:/Users/golapudipraveen/.m2/repository/org/apache/logging/log4j/
log4j-slf4j-impl/2.12.1/log4j-slf4j-impl-2.12.1.jar). If you are using
WebLogic you will need to add 'org.slf4j' to prefer-application-
packages in WEB-INF/weblogic.xml:
org.apache.logging.slf4j.Log4jLoggerFactory

LoggerFactory is not a Logback LoggerContext but Logback is on


the classpath. Either remove Logback or the competing
implementation

<?xml version="1.0" encoding="UTF-8"?>


<Configuration status="INFO">
<Appenders>
<Console name="CONSOLE" target="SYSTEM_OUT">
<JsonLayout class="ch.qos.logback.contrib.json.classic.JsonLayout">
<jsonFormatter
class="ch.qos.logback.contrib.jackson.JacksonJsonFormatter"/>
<TimestampFormat>yyyy-MM-dd HH:mm:ss.SSS</TimestampFormat>
<AppendLineSeparator>true</AppendLineSeparator>
</JsonLayout>
</Console>
</Appenders>
<Loggers>
<Root level="info">
<AppenderRef ref="CONSOLE"/>
</Root>
</Loggers>
</Configuration>

<?xml version="1.0" encoding="UTF-8"?>


<Configuration status="INFO">
<Appenders>
<Console name="CONSOLE" target="SYSTEM_OUT">
<JsonLayout properties="true">
<KeyValuePair key="timestamp" value="$${date:yyyy-MM-dd
HH:mm:ss.SSS}"/>
<KeyValuePair key="level" value="$${event:level}"/>
<KeyValuePair key="thread" value="$${main:thread}"/>
<KeyValuePair key="logger" value="$${logger:short}"/>
<KeyValuePair key="message" value="$${message}"/>
<KeyValuePair key="stackTrace" value="$${exception:format=JSON}"/>
</JsonLayout>
</Console>
</Appenders>
<Loggers>
<Root level="info">
<AppenderRef ref="CONSOLE"/>
</Root>
</Loggers>
</Configuration>

<?xml version="1.0" encoding="UTF-8"?>


<Configuration>
<Appenders>
<Console name="CONSOLE" target="SYSTEM_OUT">
<JSONLayout complete="false" compact="true" eventEol="true">
<KeyValuePair key="timestamp" value="$${date:yyyy-MM-dd
HH:mm:ss.SSS}"/>
<KeyValuePair key="stacktrace" value="$${json:exception}"/>
</JSONLayout>
</Console>
</Appenders>
<Loggers>
<Root level="info">
<AppenderRef ref="CONSOLE"/>
</Root>
</Loggers>
</Configuration>

To get exception in same String


<?xml version="1.0" encoding="UTF-8"?>
<Configuration>
<Appenders>
<Console name="CONSOLE" target="SYSTEM_OUT">
<JSONLayout complete="false" compact="true" eventEol="true">
<KeyValuePair key="timestamp" value="$${date:yyyy-MM-dd
HH:mm:ss.SSS}"/>
<KeyValuePair key="stacktrace" value="$$
{json:exception:stackAsString}"/>
</JSONLayout>
</Console>
</Appenders>
<Loggers>
<Root level="info">
<AppenderRef ref="CONSOLE"/>
</Root>
</Loggers>
</Configuration>

<?xml version="1.0" encoding="UTF-8"?>


<Configuration>
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<JsonLayout complete="false" compact="true" eventEol="true"
stacktraceAsString="true" objectMessageAsJsonObject="true">
<KeyValuePair key="timestamp" value="$${date:yyyy-MM-
dd'T'HH:mm:ss.SSSZ}"/>
<KeyValuePair key="service" value="$$
{bundle:application:spring.application.name}"/>
<KeyValuePair key="traceId" value="$${ctx:traceId}"/>
<KeyValuePair key="spanId" value="$${ctx:spanId}"/>
</JsonLayout>
</Console>
<Console name="SpringInfoLog" target="SYSTEM_OUT">
<PatternLayout>
<ScriptPatternSelector defaultPattern="%d{yyyy-MM-dd HH:mm:ss.SSS}
[%X{X-B3-TraceId},%X{X-B3-SpanId},%X{X-B3-ParentSpanId},%X{X-Span-
Export}] [%t] %-5level %c{2} - %msg%n">
<ScriptRef ref="selector"/>
<PatternMatch key="request" pattern="%d{yyyy-MM-dd
HH:mm:ss.SSS} [%X{X-B3-TraceId},%X{X-B3-SpanId},%X{X-B3-ParentSpanId},
%X{X-Span-Export}] [%t] %-5level %c{2} -service.name : $$
{bundle:application:spring.application.name} -trace-id : $${ctx:traceId} -span-id : $$
{ctx:spanId} - %msg%n%throwable -client : $${ctx:client}"/>
<PatternMatch key="default" pattern="%d{yyyy-MM-dd
HH:mm:ss.SSS} [%X{X-B3-TraceId},%X{X-B3-SpanId},%X{X-B3-ParentSpanId},
%X{X-Span-Export}] [%t] %-5level %c{2} - %msg%n"/>
</ScriptPatternSelector>
</PatternLayout>
</Console>
</Appenders>
<Loggers>
<Root level="INFO">
<AppenderRef ref="Console" />
</Root>
</Loggers>
</Configuration>

You might also like