How can I override configuration in logback-spring.xml with properties in Spring's own application.properties?

2.5k Views Asked by At

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:

0

There are 0 best solutions below