Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 626
salman irfan khandu Avatar asked May 10 '26 15:05

salman irfan khandu


1 Answers

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.

like image 117
Domenico Sibilio Avatar answered May 13 '26 04:05

Domenico Sibilio



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!