log.isDebugEnabled
我总是认为在添加log.debug
语句之前检查是否更好。
我想它应该由日志框架来处理,你能告诉我这个条件检查有什么好处吗?
Consider the following example:
if (log.isDebugEnabled()) {
log.debug("This is my complicated object" + veryComplicatedObject.toString());
}
String concatenation may be expensive (memory-wise), and there is no reason to perform it if we aren't going to log it anyway. Checking the logging level beforehand saves constructing redundant strings.
它优化,做一个检查只是节省了去上课和检查你想要报告的级别是否设置的cpu时间。如果您使用大量日志记录请求(数万或更多)或每个部分的多个日志记录请求,它只会开始有所不同。