sromit sromit - 2 years ago 268
Java Question

slf4j logger is not printing the log in console for springboot if wrapped under log.isDebugEnabled()

I am using slf4j logger in my controller class, even though my has the following entries:

#logging.level.*= DEBUG*=DEBUG

The code looks like :

private static final Logger LOGGER = LoggerFactory.getLogger(EventControllerV1.class);

public ResponseEntity<List<EventView>> requestEvents(@RequestParam("user_name") String userName) throws Exception {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("EventControllerV1:::requestEvents:::Parameters>>::userName::" + userName);
return new ResponseEntity<>(eventManager.findEvents(userName), HttpStatus.OK);


In the background slf4j uses Logback framework, but still I am not able to get the console output..but if I remove the condition and use"xxx") only , I can see the output in console when I hit the endpoint

Answer Source
if(log.isDebugEnabled()){"xxx") ;

Doesn't make much sense.

instead, it should be

  log.debug("xxx") ;

And to answer your original question,

this is not working

if(log.isDebugEnabled()){"xxx") ;

and this is working"xxx") ;

then that means, Log level for that class and method is at INFO level (which is higher than DEBUG). Try removing the * from*=DEBUG

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download