spring-projects / spring-boot

Spring Boot
https://spring.io/projects/spring-boot
Apache License 2.0
74.59k stars 40.56k forks source link

logging.threshold.file and .console do not work with level debug #42356

Closed awdm closed 5 days ago

awdm commented 5 days ago

I've tested this with a fresh Spring Boot 3.3.3 application from https://start.spring.io/ (Java 17, Maven, no dependencies).

I changed DemoApplication.java to:

package com.example.demo;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class DemoApplication {

    private static final Logger _logger = LoggerFactory.getLogger(DemoApplication.class);

    public static void main(String[] args) {

        SpringApplication.run(DemoApplication.class, args);

        _logger.warn("Test Warning");
        _logger.info("Test Info");
        _logger.debug("Test Debug");
    }
}

In application.properties I added:

logging.threshold.file=debug
logging.threshold.console=debug
logging.file.name=test.log

When I start the application, the warning and info messages are printed to both the console and the file, but the debug message is not. When I change the threshold properties to warn, only the warning messages are printed, which leads me to believe that the property is broken.

wilkinsona commented 5 days ago

I don't think it's broken. The thresholds are applied using a filter that's added to the console appender or file appender. For a log event to reach that filter, the configured log level has to have allowed it to do so. In other words, if you want a threshold of debug to have an effect, you have to have enabled some debug-level logging. If you run your application with logging.level.com.example.demo=debug, you should see the DemoApplication's debug logging being output.

You'd typically use the thresholds by configuring different values for logging.threshold.file and logging.threshold.console where you want the logging in one to be more or less verbose than the logging in the other.

awdm commented 5 days ago

Yes, that works. I wasn't aware that there's a second setting that you have to adjust. Thanks for the help.