我正在考虑将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