在多线程环境下,log4j2的异步日志系统比log4j和logback提高了十倍的性能(吞吐量和延迟率)
Log4j 2 contains next-generation Asynchronous Loggers based on the LMAX Disruptor library. In multi-threaded scenarios Asynchronous Loggers have 10 times higher throughput and orders of magnitude lower latency than Log4j 1.x and Logback.
升级面临的问题:
以前的代码都是用log4j1.X打印,log4j2的API有改动。如果在升级的过程中,我们要去改代码的话,那将是一个很繁琐的工程,log4j2架构已经考虑到这一点,给我们提供了桥连接包,我们只需要导入几个桥连接包就可以使用log4j2,而且还不需要修改代码。
Perhaps the simplest way to convert to using Log4j 2 is to replace the log4j 1.x jar file with Log4j 2's log4j-1.2-api.jar. However, to use this successfully applications must meet the following requirements:
- They must not access methods and classes internal to the Log4j 1.x implementation such as Appenders, LoggerRepository or Category's callAppendersmethod.
- They must not programmatically configure Log4j.
相关maven配置:
<!-- log4j-1.2-api为log4j和log4j2的连接包。 -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-1.2-api</artifactId>
<version>2.7</version>
</dependency>
<!-- log4j2 api -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.7</version>
</dependency>
删掉以前的log4j.properties,改为log4j2.xml。
以前使用log4j1.x API的代码不需要变动,后续代码使用Log4j2.x的API即可。