简体   繁体   中英

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(LOGGER.isDebugEnabled){...}

Also, will it have an impact on the time that an application may respond. If its not inside the if block statement?

All the log methods check for the level internally too. The reason we have isXYZEnabled methods if for performance.

Consider the following call:

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

and assume that hugeObject is, as its name suggests, huge. 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());
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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