salman irfan khandu
salman irfan khandu

Reputation: 149

Spring Boot SLF4J Logging performance

I have set log level info in my application now when I log messages with debug look like

 logger.debug("Debug logs");

will the logging framework still construct log object internally? though debug message will not be printed as application log set to info level. If log object construct then I have to write

if(logger.isDebugEnabled()) {
    logger.debug("Debug logs");
}

which looks like ugly code. Please suggest what I have to do in this case

Thank you

Upvotes: 3

Views: 1539

Answers (1)

Domenico Sibilio
Domenico Sibilio

Reputation: 1397

There is no need to wrap your logging statements with if statements as long as you use parameterized messages.

You should consider wrapping your logging statements only if they look like this and getEntry() is an expensive operation:

logger.debug("The new entry is {}.", getEntry()); 

You can refer to the SL4J logging performance documentation.

Upvotes: 3

Related Questions