[Log4j2] Spring,Hibernate,Quartz等框架集成Log4j2

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="OFF" name="log4j2config">

<Appenders>

  <Console name="console" target="SYSTEM_OUT">

    <PatternLayout pattern="%d{DEFAULT} %t %5p %c{1.}(%L) - %m%n" charset="UTF-8" />

  </Console>

</Appenders>

<Loggers>
  <Logger name="org.quartz" level="debug" additivity="false">

    <AppenderRef ref="console" />
  </Logger>

  <Logger name="org.springframework" level="debug" additivity="false">

    <AppenderRef ref="console" />

  </Logger>

  <Root level="error">
    <AppenderRef ref="rootConsole" />
  </Root>
</Loggers>

开始用上面的配置发现不行,后面知道需要加上对应框架的Log4j2的bridge

使用slf4j的加上log4j-slf4j-impl-x.x.x.jar

使用commons-logging的加上log4j-jcl-x.x.x.jar

经过测试果断行,记录一下。

下面是maven dependency

<properties>

  <log4j2.version>2.3</log4j2.version>
</properties>

<dependency>

  <groupId>org.apache.logging.log4j</groupId>
  <artifactId>log4j-api</artifactId>
  <version>${log4j2.version}</version>
</dependency>
<dependency>
  <groupId>org.apache.logging.log4j</groupId>
  <artifactId>log4j-core</artifactId>
  <version>${log4j2.version}</version>
  </dependency>
<dependency>
  <groupId>org.apache.logging.log4j</groupId>
  <artifactId>log4j-web</artifactId>
  <version>${log4j2.version}</version>
</dependency>

<dependency>
  <groupId>org.apache.logging.log4j</groupId>
  <artifactId>log4j-slf4j-impl</artifactId>
  <version>${log4j2.version}</version>
</dependency>

<dependency>
  <groupId>org.apache.logging.log4j</groupId>
  <artifactId>log4j-jcl</artifactId>

  <version>${log4j2.version}</version>

</dependency>

 

还有许多使用了slf4j作为日志的框架都可以这样配置。

Projects depending on SLF4J(基于sl4j的项目)

posted @ 2015-06-27 13:23  babi  阅读(979)  评论(0编辑  收藏  举报