When there is a logback-spring.xml
file available, if no logging config is given for the current run context, the application freezes immediately after starting. The Spring logo is printed, and then nothing else occurs.
Replication
I generated a project using https://start.spring.io/, Spring Boot version 2.2.0 M6 and adding the Spring Web dependency. Then I added the logback-spring.xml file below:
<?xml version="1.0" encoding="UTF-8"?>
<configuration additivity="false" debug="true">
<appender name="DEV_CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>[%thread] %highlight(%-5level) %cyan(%logger{15}) mdc:[%mdc] - %msg%n</pattern>
</encoder>
</appender>
<springProfile name="foo">
<root level="INFO">
<appender-ref ref="DEV_CONSOLE"/>
</root>
</springProfile>
<!-- Uncomment the following block to prevent application freezing on startup -->
<!-- <springProfile name="!foo">
<root level="TRACE">
<appender-ref ref="DEV_CONSOLE"/>
</root>
</springProfile> -->
</configuration>
Here is the entire project: demo.zip
If you simply run it with ./gradlew bootRun
, you will see the LogBack configuration debug output, then the Spring logo, and then the application hangs. This happens because the only root
logger given is for the Spring profile foo
, which is not active. If you uncomment the !foo
XML block and run again, the application will not freeze.
Desired fix
I do not think that the application should freeze, and definitely not that it should freeze silently. It would be better to throw an informative exception and fail the application startup.
Comment From: wilkinsona
Thanks for the report. The application hasn't frozen, it just hasn't logged anything. If you run your sample application it is still accessible on port 8080 and will return the expected response, for example:
$ curl localhost:8080
{"timestamp":"2019-09-23T13:54:21.997+0000","status":404,"error":"Not Found","message":"No message available","path":"/"}
The app hasn't logged anything as that is what it has been configured to do. Unfortunately, there's no way for us to tell if that's accidental or intentional so we can't output a warning or fail start up.
Comment From: garfieldnate
This was a silly mistake. Thanks for clarifying!
Comment From: rv1996
Everyone makes silly mistakes. Helped me too... Thanks.