使用像 slf4j 这样的东西的优点之一是它通过使用参数化日志来避免字符串连接。但是,当您有很长的日志消息时,如何避免性能下降?
logger.debug("This is a very long message that prints two values." +
" However since the message is long, we still incur the performance hit" +
" of String concatenation when logging {} and {} ", value1, value2);
Run Code Online (Sandbox Code Playgroud)
有没有办法避免这种性能成本,而不使用丑陋的 if 块来检查日志级别?
if (logger.isDebugEnabled()) {
logger.debug("This is a very long message that prints two values." +
" However since the message is long, we still incur the performance hit" +
" of String concatenation when logging {} and {}", value1, value2);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
819 次 |
| 最近记录: |