Spring Profile not available in Backup log on startup through Maven

I configured logback.xmlto choose which appender to use based on the active Spring profile. This technology works great when I run the application using

java -jar -Dspring.profiles.active=local path/to/target/application.war

but not when I run it using Spring Boot Maven Plugin , for example.

mvn spring-boot:run -Drun.profiles=local

Here is the corresponding logback.xml section

<root level="INFO">
    <if condition='"${spring.profiles.active}".contains("local")'>
        <then>
            <appender-ref ref="CONSOLE"/>
        </then>
        <else>
            <appender-ref ref="FILE"/>
        </else>
    </if>
</root>

I note that the profile is really correctly displayed in the application itself, it is simply not available when processing logback.xml.

The problem also manifests itself when working with the IntelliJ IDE.

Is there another way to use the Maven Spring Boot Plugin to make the profile visible to the logback.xml parser, and will it work for IntelliJ too?

+4
1

logback logback- spring extension?

logback- spring.xml :

<?xml version="1.0" encoding="UTF-8"?>
<include resource="org/springframework/boot/logging/logback/base.xml"/><!-- include  this config if you want to use spring-boot built-in appenders -->
<configuration>
    <root level="INFO">
        <springProfile name="local">
                <appender-ref ref="CONSOLE"/>
        </springProfile>
        <springProfile name="otherprofile">
                <appender-ref ref="FILE"/>
        </springProfile>
    </root>
</configuration>

logback- spring:

https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-logging.html#boot-features-logback-extensions

+2

Source: https://habr.com/ru/post/1651433/


All Articles