I've got a Spring Boot application that is deployed in a Docker container. Since Spring Boot packages an executable fat jar, so far I can only figure out how to configure Logback by including the logback.xml
inside that packaged jar's resources.
However, I don't believe this is best practice because it would require repackaging the entire jar and redeploying the jar just to configure the appender settings (for example, changing the log level or adding a new appender).
How can I package my Spring Boot application in such a way as to allow the Logback settings to be configured without needing to repackage/redeploy?
Edit: Here's my logback.xml
<configuration>
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
<file>fullLogFile.log</file>
<append>true</append>
<immediateFlush>true</immediateFlush>
<encoder>
<pattern>%-4relative [%thread] %-5level %logger{35} - %msg%n</pattern>
</encoder>
</appender>
<appender name="ROLL_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>rollingLogFile.%d{yyyy-MM-dd}.log</fileNamePattern>
</rollingPolicy>
<encoder>
<pattern>%relative [%thread] %level %logger - %msg%n</pattern>
</encoder>
</appender>
<logger name="org.my.app" level="trace" />
<root level="WARN">
<appender-ref ref="FILE"/>
<appender-ref ref="ROLL_FILE"/>
</root>
</configuration>
How can I package my Spring Boot application in such a way as to allow the Logback settings to be configured without needing to repackage/redeploy?
Just start your spring boot jar with the following parameter and put the logback.xml in the same folder with the jar. You must also remove the logback.xml from project resources.
-Dlogging.config=./logback.xml
It will then read it from there and proceed.