I would like to define a property/variable in Logback (1.2.1) that:
- Has a default value
- Can be overriden via a Java command-line option
Basically, during development, I would like Maven to be invoking the maven-surefire-plugin
with something like this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<systemPropertyVariables>
<log.dir>${project.build.directory}/logs</log.dir>
</systemPropertyVariables>
</configuration>
</plugin>
(I am sure that the above is working fine, because I have other properties being passed in for the tests this way and those work as expected).
At the moment, I have the following logback.xml
:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration>
<configuration scan="true" scanPeriod="30 seconds" debug="false">
<property name="log.dir" value="."/>
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${log.dir}/logs/my.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>strongbox_%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<fileNamePattern>strongbox-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<maxFileSize>128MB</maxFileSize>
<maxHistory>31</maxHistory>
<totalSizeCap>1GB</totalSizeCap>
<maxHistory>30</maxHistory>
</rollingPolicy>
<encoder>
<charset>UTF-8</charset>
<pattern>%d{HH:mm:ss.SSS dd-MM-yyyy} | %-5.5p | %-20.20t | %-50.50logger{50} | %m%n</pattern>
</encoder>
</appender>
...
</configuration>
The -Dlog.dir=foo/logs
, it is simply being ignored and the log file is being produced in the current directory. What am I doing wrong here? Does it need a scope? Does it need an if
condition to be set up?
logback.xml
file per environment, which is also not what I'd like to do. From what I understand, Logback supportsproperties
, which can be used inside thelogback.xml
file. I would like to be able to have a default value defined for a property inside thelogback.xml
for the cases where this is not being overriden from the console via-Dproperty1=....
. – Portal