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>
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>
I had same problem and just set this property in application.properties
:
spring.main.banner-mode=LOG
Now it prints to both console and file, with log level INFO. As long as you have your root log level and appenders set to accept INFO, you will see it.
<root level="info">
<appender-ref ref="RollingFile" />
<appender-ref ref="Console" />
</root>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With