LOGGER.isDebugEnabled() Example Java


Why LOGGER.isDebugEnabled() condition need to check in all implementation of LOG messages? 

We all know logger bring app slowness if unnecessary, message will log in place, if we implement as mention below. We can avoid/control on logging message:





e.g.:-
protected static final Logger LOG = Logger.getLogger(TutorialByExampleJavaLogger.class);
Make sure that whenever using LOG messages, check with LOGGER.isDebugEnabled() flag, so that when debugger is disabled, logs won't get printed to the log files.
e.g.:-
if(LOG. isDebugEnabled())
    { /* print your log messages as you want to print*/
       LOG.info("Info type message") ;
       //OR
       LOG.debug("Debug type message");
     }

Feel free put your point of view if any....!!!

1 comment: