Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I avoid Spring Boot Logback's fail-fast on file creation?

While starting up, Logback attempts to create/open the logging files. However, on current Spring Boot's implementation, if the files cannot be opened the application is shut down.

This seems to be an intentional behavior, as seen on SpringBoot's git.

What I would prefer is either to default to Tomcat's log, or to disable log altogether, but allowing my application to keep running. As we need to deploy it on various environments and for a short lifespan, I would rather not have to customize the log path on every instance to be deployed.

Still, I have not found any property on Spring Boot nor Logback setups which may allow me to do this.

Is there any way to bypass the IllegalStateException?

This is the error thrown on startup:

    java.lang.IllegalStateException: Logback configuration error detected: 
    ERROR in ch.qos.logback.core.rolling.RollingFileAppender[FILE-MESSAGES-BODIES] - Failed to create parent directories for [C:\MY_PATH\file.log]
    ERROR in ch.qos.logback.core.rolling.RollingFileAppender[FILE-MESSAGES-BODIES] - openFile(C:\MY_PATH\file.log,true) call failed. java.io.FileNotFoundException: C:\MY_PATH\file.log (The device is not ready)
    ERROR in ch.qos.logback.core.rolling.RollingFileAppender[FILE-LOG] - Failed to create parent directories for [C:\MY_PATH\file.log]

Using Spring Boot (v1.5.3)

like image 271
Daniel Avatar asked May 15 '17 13:05

Daniel


People also ask

Which logging framework is best for spring boot?

If you are using Spring Boot Starters, Logback will provide a good support for logging. Besides, Logback also provides a use of good support for Common Logging, Util Logging, Log4J, and SLF4J.

How do I disable Logback?

Logback does not allow logging to be disabled from the command line. However, if the configuration file allows it, you can set the level of loggers on the command line via a Java system property.

Does spring boot use Logback by default?

By default, Spring Boot picks up the native configuration from its default location for the system (such as classpath:logback.


1 Answers

As mentioned in the documentation you can configure the org.springframework.boot.logging.LoggingSystem system property with a value of none to disable Spring Boot's logging system. You can then use logback.xml as you usually would to configure logging, or omit it to use Logback's default configuration.

like image 50
Andy Wilkinson Avatar answered Sep 20 '22 08:09

Andy Wilkinson