How to send java.util.logging to log4j?

前端 未结 7 1378
囚心锁ツ
囚心锁ツ 2020-11-29 02:51

I have an existing application which does all of its logging against log4j. We use a number of other libraries that either also use log4j, or log against Commons Logging, wh

7条回答
  •  误落风尘
    2020-11-29 03:20

    There is a simpler alternative than SLF4J to bridge JUL with log4j, see http://people.apache.org/~psmith/logging.apache.org/sandbox/jul-log4j-bridge/examples.html

    You just have to put the jul-log4j-bridge on the classpath and add a system property:

    -Djava.util.logging.manager=org.apache.logging.julbridge.JULBridgeLogManager
    

    jul-log4j-bridge is not in Maven Central and can be fetched from this repository:

    
      psmith
      http://people.apache.org/~psmith/logging.apache.org/repo
      
        false
      
    
    

    and then used with:

    
      org.apache.logging
      apache-jul-log4j-bridge
      1.0.0-SNAPSHOT
      test
      
        
          log4j
          apache-log4j-component
        
      
    
    

    It's also possible to rebuild it from sources with the following steps:

    1. svn co http://svn.apache.org/repos/asf/logging/sandbox/jul-to-log4j-bridge/
    2. edit pom.xml, replace the dependency on log4j:log4j:1.2.15 with log4j:apache-log4j-extras:1.2.17 and remove the dependency on apache-log4j-component
    3. mvn package

提交回复
热议问题