3

log.isDebugEnabled我总是认为在添加log.debug语句之前检查是否更好。

我想它应该由日志框架来处理,你能告诉我这个条件检查有什么好处吗?

4

2 回答 2

1

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.

于 2013-09-26T21:19:52.633 回答
0

它优化,做一个检查只是节省了去上课和检查你想要报告的级别是否设置的cpu时间。如果您使用大量日志记录请求(数万或更多)或每个部分的多个日志记录请求,它只会开始有所不同。

于 2013-09-26T21:19:09.810 回答