In my Spring Boot project, I initially set up the logging configuration in the application.properties, e.g.
logging.file=/foo/bar/app.log
logging.file.max-size=1M
logging.file.max-history=10
logging.file.level.root=DEBUG
logging.file.level.root.com.my.app=DEBUG
logging.file.level.org.springframework.boot.diagnostics=DEBUG
logging.file.level.org.springframework.security=DEBUG
Let's say I have other environment-specific properties files named following this pattern application-xxx.properties
with xxx
being the Spring profile name passed as argument when running the app (via -Dspring.profiles.active=xxx
).
In these files, I can override the log levels, e.g. for an application-qa.properties
logging.file.level.root=INFO
logging.file.level.root.com.my.app=INFO
logging.file.level.org.springframework.boot.diagnostics=INFO
logging.file.level.org.springframework.security=INFO
I can also override these in the command line with the same mechanism as explained above (-D
).
Now, I'm asked to transfer all this configuration into a single logback-spring.xml
. Using this new style of configuration, is there a way to still override each properties?
Found these resources while looking for an answer:
- neither official Spring doc: https://docs.spring.io/spring-boot/docs/current/reference/html/features.html#features.logging
- nor this DZone article mention that: https://dzone.com/articles/configuring-logback-with-spring-boot
- this article on CodeJava: https://www.codejava.net/frameworks/spring-boot/logback-rolling-files-example even says it works the other way round: The configuration in XML file will override the logging properties in the application.properties file. !!!