2017-05-15 35 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的默認配置。