sromit
sromit

Reputation: 1112

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 application.properties has the following entries:

#logging.level.*= DEBUG
logging.level.org.springframework.web=DEBUG
logging.level.com.ge.power.brs.controllers.*=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 log.info("xxx") only , I can see the output in console when I hit the endpoint

Upvotes: 2

Views: 22529

Answers (2)

Gene
Gene

Reputation: 11267

Inside "src/main/resources/application.properties" file, add this:

logging.level.com.mypackage.name=INFO

So for example:

logging.level.com.yourbusiness=INFO

If you want it all, then try

logging.level.com=INFO

The ".com" part refers to anything inside src/main/java/com. So for my project, I have src/main/java/com/yourbusiness

Upvotes: 2

so-random-dude
so-random-dude

Reputation: 16465

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

Doesn't make much sense.

instead, it should be

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

And to answer your original question,

this is not working

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

and this is working log.info("xxx") ;

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

Upvotes: 2

Related Questions