java – 使用slf4j和log4j与单独使用log4j有任何性能开销吗?
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了java – 使用slf4j和log4j与单独使用log4j有任何性能开销吗?,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1220字,纯文字阅读大概需要2分钟。
内容图文
![java – 使用slf4j和log4j与单独使用log4j有任何性能开销吗?](/upload/InfoBanner/zyjiaocheng/752/edf33b77c222475cb1970f23e02dcef8.jpg)
我正在考虑将java 1.4.2项目从log4j迁移到slf4j.这是参数化日志记录和代码清晰度的优点(不需要log.isdebug ..)这让我想到了这样的考虑.
是否有转换为slf4j的性能开销?
上次我检查是否可以使用logback时,它对jdk有一个要求,它要求它至少为1.5,这就是我考虑slf4j和log4j的原因.
解决方法:
不,你应该从slf4j获得性能优势,如果有的话,因为(如果你使用参数化消息)那么slf4j defers turning its parameters to strings until it has checked that the message won’t be filtered out by log level:
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 – 使用slf4j和log4j与单独使用log4j有任何性能开销吗?全部内容,希望文章能够帮你解决java – 使用slf4j和log4j与单独使用log4j有任何性能开销吗?所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。