Lo4j1.x 迁移到 Log4j2.x

在多线程环境下,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:

  1. They must not access methods and classes internal to the Log4j 1.x implementation such as Appenders, LoggerRepository or Category's callAppendersmethod.
  2. 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即可。

 

转载于:https://my.oschina.net/trydaydayup/blog/1604992

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值