简体   繁体   English

如果日志记录级别为信息,logger.debug 是否可能产生错误

[英]Is it possible for logger.debug to produce error if logging level is info

I'm new to loggers and I just wanted to ask if i will get an error if my log level is info, then i have something like:我是记录器的新手,我只是想问如果我的日志级别是信息,我是否会收到错误,然后我有类似的东西:

logger.debug("hello " + object.getMethod());

And it is not inside an if block like below:它不在像下面这样的 if 块内:

if(LOGGER.isDebugEnabled){...}

Also, will it have an impact on the time that an application may respond.此外,它是否会影响应用程序可能响应的时间。 If its not inside the if block statement?如果它不在 if 块语句中?

All the log methods check for the level internally too.所有日志方法也在内部检查级别。 The reason we have isXYZEnabled methods if for performance.如果为了性能,我们有isXYZEnabled方法的原因。

Consider the following call:考虑以下调用:

logger.debug("Value of myObject is: " + hugeObject.toString());

and assume that hugeObject is, as its name suggests, huge.并假设hugeObject对象,顾名思义,是巨大的。 Constructing a string representation of it might be both time and memory consuming, and ultimately pointless, since after you created the string, nothing will be logged if the level isn't set to debug.构建它的字符串表示可能既耗时又耗内存,最终毫无意义,因为在创建字符串之后,如果级别未设置为调试,则不会记录任何内容。 Instead, you could explicitly check the level before performing this converstion, and save the time it could have taken:相反,您可以在执行此转换之前明确检查级别,并节省可能花费的时间:

if (logger.isDebugEnabled()) {
    logger.debug("Value of myObject is: " + hugeObject.toString());
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM