哪个配置文件是Logback使用的?

时间:2016-11-25 13:38:13

标签: logback slf4j

是否有系统属性使Slf4J和Logback告诉它找到了哪些logback.xmllogback-test.xml文件以及它使用了哪个?我希望在日志本身或System.out中看到它。

例如,我有一个明显没有src/main/resources/logback.xmlsrc/test/resources/logback-test.xml文件的Java项目,但是当我运行单元测试时,Logback确实找到了一个。我确实有多达100个依赖项(理论上没有一个应该包含logback.xml)并且逐个检查它们是不切实际的。

请注意,我无法在配置文件中使用<configuration debug="true">,因为我不知道配置文件的开头位置。我想要同样的效果。

1 个答案:

答案 0 :(得分:0)

在评论中使用Tony所述的-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 ch.qos.logback.classic.joran.JoranConfigurator@1e965684 - 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)。