I am trying to use JUL Adapter to delegate Java Util Logging to Log4j2. More precisely, any third-party library that use JUL to generate logs, should be delegat
java.util.logging.LogManager
class gets initialized when web application container like tomcat
, gretty
gets started. At the time of loading (in static block
), this class checks for the value of java.util.logging.manager
system property and create the Logger
accordingly. Once initialized, this class never gets initialized again.
So, for a web application, setting this system property through web application code would be too late.
One possible solution is to pass this system property value through VM arguments
to the application container -
-Djava.util.logging.manager="org.apache.logging.log4j.jul.LogManager"
In this situation, you have to provide log4j
jars and configuration file at the time of starting container so that org.apache.logging.log4j.jul.LogManager
can be loaded through System ClassLoader
.
For tomcat, following 3 jars you must load along with bootstrap.jar
(tomcat startup), tomcat-juli.jar
(logging) to make it work -
log4j-jul
log4j-api
log4j-core
Similar approach needs to be used for other container also.