java Logback.xml 没有登录到 ConsoleAppender?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12443569/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Logback.xml not logging to ConsoleAppender?
提问by Alterscape
I'm trying to set up a console logger with logback in slf4j. My logback configuration is as follows:
我正在尝试在 slf4j 中设置一个带有 logback 的控制台记录器。我的logback配置如下:
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<!-- encoders are assigned the type
ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<pattern>%-4relative [%thread] %-5level %logger{35} - %msg %n</pattern>
</encoder>
</appender>
<logger name="org.hibernate" level="INFO" />
<logger name="com.myapp" level="TRACE" />
<root level="DEBUG">
<appender-ref ref="STDOUT" />
</root>
</configuration>
Even though Logback seems to set up with no problems, I can't seem to get output from any loggers into my console. I have tested that LOGGER.isInfoEnabled() returns true in my app.
尽管 Logback 似乎设置没有问题,但我似乎无法将任何记录器的输出输入到我的控制台中。我已经测试过 LOGGER.isInfoEnabled() 在我的应用程序中返回 true。
The output of Logback's StatusPrinter:
Logback 的 StatusPrinter 的输出:
17:25:11,736 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback-test.xml]
17:25:11,737 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Found resource [logback.xml] at [file:/Users/ryanspicer/NetBeansProjects/Oncewhen/build/classes/logback.xml]
17:25:11,996 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - debug attribute not set
17:25:11,996 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.ConsoleAppender]
17:25:12,000 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [STDOUT]
17:25:12,038 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@12:74 - no applicable action for [encoder], current pattern is [[configuration][appender][encoder]]
17:25:12,038 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@13:16 - no applicable action for [pattern], current pattern is [[configuration][appender][encoder][pattern]]
17:25:12,038 |-ERROR in ch.qos.logback.core.ConsoleAppender[STDOUT] - No layout set for the appender named "STDOUT".
17:25:12,038 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Popping appender named [STDOUT] from the object stack
17:25:12,038 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [org.hibernate] to INFO
17:25:12,038 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting additivity of logger [org.hibernate] to true
17:25:12,038 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [com.myapp] to TRACE
17:25:12,038 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting additivity of logger [com.myapp] to true
17:25:12,038 |-INFO in ch.qos.logback.classic.joran.action.RootLoggerAction - Setting level of ROOT logger to DEBUG
17:25:12,038 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [STDOUT] to Logger[root]
Any ideas what might be going on here, and how to fix it and get working log output?
任何想法这里可能会发生什么,以及如何修复它并获得工作日志输出?
采纳答案by Ceki
From the status output, it looks like you are using a version of logback 0.9.18 or earlier. You should try with the latest version.
从状态输出来看,您似乎使用的是 logback 0.9.18 或更早版本。您应该尝试使用最新版本。
回答by Jake Collins
For those who need to use logback 0.9.18 due to third party dependencies, see this answer for an example of how to configure the appenders.
对于由于第三方依赖而需要使用 logback 0.9.18 的人,请参阅此答案以获取有关如何配置 appender 的示例。