1

I have following variable in logback-sring.xml and I want to override its default value using value supplied in command line.

<property name="log_root" value="${log.root:-logapp/logs}"/>
 <appender name="file" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${log_root}/app.log</file>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <fileNamePattern>${log_root}/archived/app.%d{yyyy-MM-dd}.log</fileNamePattern>
            <!-- keep 30 days worth of history, but at most 1GB -->
            <totalSizeCap>1GB</totalSizeCap>
            <maxHistory>30</maxHistory>
        </rollingPolicy>
        <encoder>
            <pattern>%level %d [%thread] %logger{15} - %msg %ex{2}%nopex%n</pattern>
        </encoder>
    </appender>

I tried to override the value during the jar call:

java -jar app.jar -Dlog.root=logappv2/logs

But the app always use the default log.root value. What is possibly the cause?

1
  • Please include the part of logback-spring.xml referring log_root Commented Dec 18, 2023 at 14:10

2 Answers 2

1

You should put -Dlog.root=logappv2/logs before -jar, like.

java -Dlog.root=logappv2/logs -jar app.jar

Reference: Proper usage of Java -D command-line parameters

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

Comments

0

This is the variable you are passing via command line ${log.root} but I do not see its usage.

1 Comment

i have added the usage

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.