How to send java.util.logging to log4j?

前端 未结 7 1279
囚心锁ツ
囚心锁ツ 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:

    <repository>
      <id>psmith</id>
      <url>http://people.apache.org/~psmith/logging.apache.org/repo</url>
      <releases>
        <enabled>false</enabled>
      </releases>
    </repository>
    

    and then used with:

    <dependency>
      <groupId>org.apache.logging</groupId>
      <artifactId>apache-jul-log4j-bridge</artifactId>
      <version>1.0.0-SNAPSHOT</version>
      <scope>test</scope>
      <exclusions>
        <exclusion>
          <groupId>log4j</groupId>
          <artifactId>apache-log4j-component</artifactId>
        </exclusion>
      </exclusions>
    </dependency>
    

    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
    0 讨论(0)
提交回复
热议问题