Hey,
So I've just switched my logging framework to Log4j2 to leverage it's
support for MDC. Given that I've used a mixture of SLF4J and JUL log
messages within my code I've decided to leverage Log4j ability to
convert JUL log messages to Log4j2 messages. I've set the following flag
to my application
-Djava.util.logging.manager=org.apache.logging.log4j.jul.LogManager and
added all the required jars. Logging seems to be working pretty good in
that my SLF4J and JUL messages are being formatted according to my
log4j2 config file I added a Hello prefix to each message, though MDC
seems to not be picked up with the JUL messages.
From debugging when I use the SLF4J logger it calls Log4jLogger which
is preserving the ThreadContext whereas my JUL log messages are
re-initializing the ThreadContext as soon as they enter AbstractLogger.
Anyone know if it's possible to preserve ThreadContext with JUL messages
being converted to Log4j2 messages or is there a potential alternative
method I can look into?
My Log4j2.xml config file:
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="INFO">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="Hello %X{Organisation}
%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
</Console>
</Appenders>
<Loggers>
<Root level="info">
<AppenderRef ref="Console"/>
</Root>
</Loggers>
</Configuration>
Regards,
Abdul Haseeb Hussain
--
*The information in this email is confidential and solely for the use of
the intended recipient(s). If you receive this email in error, please
notify the sender and delete the email from your system immediately. In
such circumstances, you must not make any use of the email or its contents.
Views expressed by an individual in this email do not necessarily reflect
the views of Matillion Ltd.
*
*Matillion Ltd accepts no responsibility
for any damage caused by malicious software transmitted by email. Email
transmission cannot be guaranteed to be secure and error free, it is
possible for it to be intercepted, lost, destroyed, later, incomplete or
with added malware. The sender does not accept liability for any errors or
omissions in the contents of this message, which arise as a result of email
transmission
*
*Matillion Ltd, Station House, Stamford New Road,
Altrincham, England, WA14 1EP (Main and registered office address).
*_Company number: 07474948._