I spent a lot of time setting up Logback to work with Spring Boot , and I would like to share my configuration, hoping to save other people from wasting my time.
My example is similar to Andy Dufresne above, with one key difference - the <property> . This was really important in my case, because if you include <property name="logs_dir" value="." /> <property name="logs_dir" value="." /> , you cannot override it with the system properties, which I would like to do as follows:
java -jar -Dlogs_dir=~/newLogsDir yourApp.jar
Also note that the default value is set in the path variable - ${logs_dir:-.} . Hope this helps:
<?xml version="1.0" encoding="UTF-8"?> <configuration> <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder"> <pattern>%-20(%d{yyyy-MM-dd HH:mm:ss} %highlight([%-5level])) %msg%n</pattern> </encoder> </appender> <appender name="ROLLING" class="ch.qos.logback.core.rolling.RollingFileAppender"> <file>${logs_dir:-.}/system.log</file> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <fileNamePattern>system-%d{yyyy-MM}.log.zip</fileNamePattern> <maxHistory>12</maxHistory> <totalSizeCap>3GB</totalSizeCap> </rollingPolicy> <encoder> <pattern>%-26(%d [%-5level]) %logger{35} - %msg%n</pattern> </encoder> </appender> </configuration>
source share