JUL Adapter not working for Jersey

前端 未结 3 898
-上瘾入骨i
-上瘾入骨i 2021-02-15 13:10

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

3条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-15 13:49

    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.ju‌​l.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.

提交回复
热议问题