2015-04-14 96 views
0

我有,我已經創建了一個logback.xml配置文件非常簡單的Spring 1.2.2啓動Web應用程序:春天啓動的logback fileappender配置

<configuration debug="true" scan="true" scanPeriod="33 seconds"> 

    <appender name="console" class="ch.qos.logback.core.ConsoleAppender"> 
     <encoder> 
     <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern> 
    </encoder> 
    </appender> 

<!-- 
    <appender name="logfile" class="ch.qos.logback.core.FileAppender"> 
    <file>myapp.log</file> 
    <append>true</append> 
    <encoder> 
     <pattern>%d{HH:mm:ss.SSS %-5level [%thread] %logger{10} [%file:%line] %msg%n</pattern> 
    </encoder>  
    </appender> 
--> 

    <logger name="com.myapp.logtest.SampleController" level="DEBUG"/> 
    <logger name="com.myapp.logtest" level="WARN"> 
    </logger> 

    <root level="INFO"> 
    <appender-ref ref="console"/> 
    </root> 

</configuration> 

一切的偉大工程!這裏是日誌文件的調試輸出:

12:29:16,397 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - Setting ReconfigureOnChangeFilter scanning period to 33 seconds 
12:29:16,397 |-INFO in ReconfigureOnChangeFilter{invocationCounter=0} - Will scan for changes in [[...\logtest\logback.xml]] every 33 seconds. 
12:29:16,397 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - Adding ReconfigureOnChangeFilter as a turbo filter 
12:29:16,397 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.ConsoleAppender] 
12:29:16,397 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [console] 
12:29:16,407 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property 
12:29:16,427 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [com.myapp.logtest.SampleController] to DEBUG 
12:29:16,427 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [com.myapp.logtest] to WARN 
12:29:16,427 |-INFO in ch.qos.logback.classic.joran.action.RootLoggerAction - Setting level of ROOT logger to INFO 
12:29:16,427 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [console] to Logger[ROOT] 
12:29:16,427 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - End of configuration. 
12:29:16,427 |-INFO in [email protected] - Registering current configuration as safe fallback point 

現在,這是我的問題。如果我對配置文件中的文件appender進行了UNCOMMENT,即使沒有對其進行參考,我的整個logback配置也會被丟棄,並且我的應用程序會回到使用Spring日誌記錄的默認值。這裏是的logback調試輸出本文件的appender:

12:32:58,308 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - Setting ReconfigureOnChangeFilter scanning period to 33 seconds 
12:32:58,308 |-INFO in ReconfigureOnChangeFilter{invocationCounter=0} - Will scan for changes in [[...\logtest\logback.xml]] every 33 seconds. 
12:32:58,308 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - Adding ReconfigureOnChangeFilter as a turbo filter 
12:32:58,308 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.ConsoleAppender] 
12:32:58,308 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [console] 
12:32:58,328 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property 
12:32:58,338 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.FileAppender] 
12:32:58,338 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [logfile] 
12:32:58,338 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property 
12:32:58,348 |-WARN in Logger[org.springframework.boot.logging.LoggingApplicationListener] - No appenders present in context [default] for logger [org.springframework.boot.logging.LoggingApplicationListener]. 

正如你可以看到,該文件的存在本身附加器的logback導致初始化與LoggingApplicationListener警告停止。 Logback實例化文件appender,所以我相信它在logback.xml中正確指定。但是我的logback.xml被忽略,並且日誌記錄回落到Spring默認值。

這個警告是什麼意思?我如何獲得一個logback文件appender來使用Spring啓動?

回答

0

檢查應用程序屬性中是否有。如果在application.properties中存在類似此類的任何內容,則logback.xml將被忽略,並將默認爲application.properties中的內容。