为啥打日志时要加个isInfoEnabled

为啥在进行日志输出之前加个logger.isInfoEnabled()这样的判断呢?
log文档这样的说明:

log.Info("Entry number: " + i + " is " + entry[i].ToString());

‘incurs the cost of constructing the message parameter, i.e. converting both integer i and entry[i] to strings, and concatenating intermediate strings, regardless of whether the message will be logged or not’……
不管是Integer还是对象数组,都会被转成String进行拼接,就算当前的日志级别小于系统里设置的日志级别。而加了判断之后,只有当前的日志级别大于或等于系统设置的级别才会进行拼接

评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理