1

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 Answers 3

1

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

Sign up to request clarification or add additional context in comments.

Comments

0

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"/>

1 Comment

logback base file is not of use for me. I have several different customized appenders for different log files and i need to configure the log path because they are used by several different applications.
0

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.

1 Comment

This not an answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.