java log4j 性能_java – 使用slf4j和log4j与单独使用log4j有任何性能开销吗?

我正在考虑将java 1.4.2项目从log4j迁移到slf4j.这是参数化日志记录和代码清晰度的优点(不需要log.isdebug ..)这让我想到了这样的考虑.

是否有转换为slf4j的性能开销?

上次我检查是否可以使用logback时,它对jdk有一个要求,它要求它至少为1.5,这就是我考虑slf4j和log4j的原因.

解决方法:

There exists a very convenient alternative based on message formats. Assuming entry is an object, you can write:

Object entry = new SomeObject();

logger.debug("The entry is {}.", entry);

After evaluating whether to log or not, and only if the decision is affirmative, will the logger implementation format the message and replace the ‘{}’ pair with the string value of entry. In other words, this form does not incur the cost of parameter construction in case the log statement is disabled.

The following two lines will yield the exact same output. However, the second form will outperform the first form by a factor of at least 30, in case of a disabled logging statement.

logger.debug("The new entry is "+entry+".");

logger.debug("The new entry is {}.", entry);

标签:java,log4j,slf4j

来源: https://codeday.me/bug/20190723/1515336.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值