1
votes

I have my own logback base.xml file where i define pre-defined file appenders that are used by different applications. I want the log directory to be configurable per application with a property in application.properties (log.path) and have a default in case none is provided (/var/log), so i have:

base.xml

<included>
<property name="logPath" value="${logPath:-/var/log}"/>   
<appender name="TEST" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <file>${logPath}/test.log</file>
    ...
</appender>

logback-spring.xml for spring boot application:

<configuration>
<springProperty scope="context" name="logPath" source="log.path" />
<include resource="base.xml" />
    <root level="INFO">
        <appender-ref ref="TEST"/>
    </root>
</springProfile>

For some reason i end up with two log directories, both /var/log and "log.dir", it seems base.xml is interpreted before spring boot environment is ready.

I'm running spring-boot 1.5.2 comes with logback 1.1.11.

3

3 Answers

1
votes

It seems the problem was caused by adding spring-cloud.

During spring cloud's boostraping process, log.dir property is not found and logback creates an logDir_IS_UNDEFINED directory. After the bootstrap process logback is re-initialized with right configuration.

Related spring-cloud issue: issue-197

0
votes

See Spring Documentation, especially the section about how properties are carried over to logback. Try using logging.path as a property in your application.properties. It should be accessible as LOG_PATH in logback than.

Also the usual way to use the base file is by adding the spring-boot-starter-logging in Maven/Gradle and include it like that:

<include resource="org/springframework/boot/logging/logback/base.xml"/>
0
votes

I have a similar problem. I use defaultValue. To be honest it's just a smelly workaround.

<springProperty name="configurable.canonical.name" source="canonical.name" defaultValue="${canonical_name}" />

<file>logs/${configurable.canonical.name}.log</file>

canonical_name is defined in default.properties. Maven is going to resolve it during build.