2017-05-15 39 views
2

启动时,Logback会尝试创建/打开日志文件。但是,在当前Spring Boot的实现中,如果文件无法打开,应用程序将被关闭。如何在创建文件时避免Spring Boot Logback的快速失败?

这似乎是一种故意行为,如SpringBoot's git所示。

我更喜欢的是默认Tomcat的日志,或者完全禁用日志,但允许我的应用程序继续运行。由于我们需要将其部署在各种环境中并且寿命短,我宁愿不必为每个要部署的实例定制日志路径。

不过,我还没有发现有关Spring Boot的任何属性,也没有发现可能允许我这样做的Logback设置。

有什么办法可以绕过IllegalStateException

这是扔在启动时出现错误:

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] 

使用Spring启动(V1.5.3)

回答

1

正如mentioned in the documentation你可以用none值配置org.springframework.boot.logging.LoggingSystem系统属性禁用春天启动的日志系统。然后,您可以像平常那样使用logback.xml来配置日志记录,或者省略它以使用Logback的默认配置。