If you use spring boot to run your application, you can:
logback.xml
<?xml version="1.0" encoding="UTF-8"?> <configuration> <property file="${configuration.file.path}" /> ....... </configuration>
You can change the "configuration.file.path", but you must change this name after starting your application.
You can use the properties defined in the properties file as follows:
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> <layout class="ch.qos.logback.classic.PatternLayout"> <Pattern> %d{yyyy-MM-dd HH:mm:ss} - ${property.defined.in.property.file} - %msg%n </Pattern> </layout> </appender> <root level="${level.defined.in.property.file}"> <appender-ref ref="STDOUT" /> </root>
And add the parameter to the virtual machine when running your application
-Dlogging.config=/some/path/logback.xml -Dconfiguration.file.path=/other/path/application.properties
logging.config is a spring-boot configuration, so you must keep this name. You can change this file in each execution without changing the configuration in your application.
if you run your application manually on the command line, it should look like:
java -Dlogging.config=/some/path/logback.xml -Dconfiguration.file.path=/other/path/application.properties -jar app-1.0.0.jar .....
Performing this task, the entire logging configuration is dynamic, and you provide it when the application starts. You may have different instances with different configurations.
Motakjuq
source share