使用类似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);
有没有办法避免这种性能成本,而不使用丑陋的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);
}
答案 0 :(得分:4)
没有字符串连接。
编译器将为您创建一个长字符串文字。