Display Spring-Boot Banner with Root-Logger WARN

Hannes :

Under development and test environment the ROOT logger level is DEBUG or INFO. The spring-boot banner is displayed at application startup:

2017-03-23 14:31:00,322 [INFO ]                 - 
 :: Spring Boot ::         (v1.5.2.RELEASE)
 :: Application ::         AcMe (v1.0-SNAPSHOT)
 :: Build ::               2017-03-23 09:53

But when running in a production environment the my ROOT logger level is normally WARN. This causes the banner not to be printed out.

How to configure logback so that the banner will be displayed also in production?

My guess was to add another logger, but the following (and alike configuration) did not work:

<logger name="org.springframework.web" level="INFO" additivity="false">
    <appender-ref ref="FILE"/>
</logger>

Here my configuration

application.properties:

  spring.main.banner-mode=log

application-devel.properties:

  logging.config=classpath:logging-spring-devel.xml

application-production.properties:

  logging.config=classpath:logging-spring-production.xml

logging-devel.xml (banner displayed)

        LOG_PATH:-${LOG_TEMP:-${java.io.tmpdir:-/tmp}}/}application.log}"/>
        <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
            <file>${LOG_FILE}</file>
            ...
        </appender>
        <root level="INFO">
            <appender-ref ref="FILE"/>
        </root>
    </configuration>

logging-production.xml (banner not displayed)

        LOG_PATH:-${LOG_TEMP:-${java.io.tmpdir:-/tmp}}/}application.log}"/>
        <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
            <file>${LOG_FILE}</file>
            ...
        </appender>
        <root level="WARN">
            <appender-ref ref="FILE"/>
        </root>
    </configuration>
Sasha Shpota :

During printing a banner Spring Boot uses logger of class org.springframework.boot.SpringApplication with INFO level.

The simples solution would be to enable INFO level for this particular class:

<logger name="org.springframework.boot.SpringApplication"
        level="INFO" additivity="false">
    <appender-ref ref="FILE"/>
</logger>

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=456314&siteId=1