If what you want is just changing log level, then should follow the approach in jccampanero's answer. That is provided by Spring boot out of the box to make things simple for developers.
However, if you want to do more customization on the logging, and you want to have the flexibility to pass config values from application.properties
or application.yml
to your logback-spring.xml
. It is also very simple.
For example in application.properties
you have this config my.logging.level=WARN
In your logback-spring.xml
you can simply retrieve it by this
<springProperty scope="context" name="logLevel" source="my.logging.level" defaultValue="INFO"/>
And now you can use logLevel
(as defined in the springProperty tag above) in your logback-spring.xml
file like this:
<root level="${loglevel}">
<appender-ref ref="CONSOLE"/>
</root>
Hope you find this helpful.