2016-11-25 59 views
0

是否有一個系統屬性可以讓Slf4J和Logback知道它找到了哪個logback.xmllogback-test.xml文件以及它正在使用哪個文件?我期望在日誌本身或System.out中看到。Logback使用哪個配置文件?

例如,我有一個Java項目,顯然沒有src/main/resources/logback.xml也沒有src/test/resources/logback-test.xml文件,但Logback似乎在我運行我的單元測試時找到一個。我確實有多達100個依賴關係(理論上應該包括logback.xml)並且逐個檢查它們是不切實際的。

請注意,我不能在我的配置文件中使用<configuration debug="true">,因爲我不知道我的配置文件在哪裏開始。我想同樣的效果。

+1

嘗試使用'-Dlogback.debug = true'運行您的應用程序http://stackoverflow.com/questions/3802054/run-logback-in-debug – tony19

回答

0

使用-Dlogback.debug=true正如託尼在評論中所述。 那麼這表明了:

15:14:22,155 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback.groovy] 
15:14:22,156 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Found resource [logback-test.xml] at [file:/.../target/test-classes/logback-test.xml] 
15:14:22,333 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.ConsoleAppender] 
15:14:22,338 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [consoleAppender] 
15:14:22,354 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property 
15:14:22,378 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [org.optaplanner] to INFO 
15:14:22,379 |-INFO in ch.qos.logback.classic.joran.action.RootLoggerAction - Setting level of ROOT logger to WARN 
15:14:22,379 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [consoleAppender] to Logger[ROOT] 
15:14:22,379 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - End of configuration. 
15:14:22,380 |-INFO in [email protected] - Registering current configuration as safe fallback point 

從中明確此行重要的:

... - Found resource [logback-test.xml] at [file:/.../target/test-classes/logback-test.xml] 

如果沒有顯示出來,它或者使用默認的日誌配置(一切DEBUG)或無法識別的系統屬性。祝你好運算出它是哪種情況(vote for this jira)。

+0

Slf4j不支持-Dslf4j.debug還未找出哪些日誌記錄實現被使用。 [爲此傑拉投票](http://jira.qos.ch/browse/SLF4J-381) –