Console logging in development is a must, but it would be nice to have a simple way to disable console logging in non-development environments, ideally without the need to create and maintain logback xml.
Our current solution:
- In development (application.properties) we have no additional logging configuration as the defaults work great!
- In production (application-prod.properties) we log to a file and disable (via a hack) console logging:
logging.pattern.console =
logging.level.root = WARN
logging.file.name = /var/log/app_logs/WebApp.log
This approach is based on a tip from https://www.baeldung.com/spring-boot-disable-console-logging#logback
Alternatively, we can avoid creating the XML file by overriding the default configuration with application properties. For example, we can potentially make use of the logging.pattern.console property:
logging.pattern.console=
Since upgrading to Spring Boot 3.5.4 (from 3.4) we see this error in Tomcat's catalina.out reminding us of this workaround:
-ERROR in ch.qos.logback.classic.PatternLayout("") - Empty or null pattern.
Is it feasible and appropriate to add a configuration property to disable console logging? This idea has been hinted at in the past.
Comment From: ThomasVitale
@BriceRoncace thanks for reporting this issue, I experienced the same problem. The logging.pattern.console=
hack is the only way I'm aware of to disable console logging in CLI applications. It's also the recommended option in the Spring Shell documentation.
I build CLI applications with Spring Boot and Spring Shell and since I upgraded to Spring Boot 3.5, every CLI command triggers the print of the Logback error message, which is really unfortunate.
I haven't found any way to disable that error message via Spring configuration.
Comment From: wilkinsona
We discussed this today and would like to introduce logging.console.enabled
that can be set to false
to disable console logging.
Comment From: philwebb
I think logging.threshold.console=off
will filter console logging so perhaps we can make logging.console.enabled
just set that.