sparkyspider
sparkyspider

Reputation: 13529

Logging not working in Spring Boot (Gradle)

I have an interceptor which I'm trying to use to log:

package com.noxgroup.nitro.security;
...

import org.slf4j.Logger; import org.slf4j.LoggerFactory;

@Component
public class SecurityInterceptor implements HandlerInterceptor {

private static final Logger log = LoggerFactory.getLogger(SecurityInterceptor.class);

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handlingObject) throws Exception {
        log.debug("Interceptor firing...");
    }
}

So I configured application.properties as such:

debug=true
logging.level.org.springframework.web=DEBUG
logging.level.com.noxgroup.nitro=DEBUG
logging.level.com.noxgroup.nitro.security=DEBUG

But no suck luck. Nothing appearing in the console. System.out.println does work though.

Note: I'm using spring-boot-starter-web which I'm under the impression has an implementation of Apache Commons Logging within it...

Edit: I can log info, but debug isn't logging.

Upvotes: 0

Views: 3671

Answers (2)

sparkyspider
sparkyspider

Reputation: 13529

The problem turned out three-fold:

  1. Correctly, as @Sanjay suggested, I needed to specify the actual package, and not assume that a higher level package will filter down. This allowed me to log level info but not level debug
  2. I wasn't actually using application.properties. I had a Spring @Configuration class that was loading a properties file, on-the-fly. It actually needs to be in the spring detected application.properties
  3. I was using JULI, where as SLF4J is actually implemented with Logback in Spring Boot.

Upvotes: 1

Sanjay
Sanjay

Reputation: 8965

Did you try to set the level to DEBUG for your own package, i.e.

logging.level.com.noxgroup.nitro.security=DEBUG

To run every log in DEBUG mode, you can also try

logging.level.=DEBUG

Upvotes: 4

Related Questions