gpt4 book ai didi

java - Logback 找不到资源 logback.xml

转载 作者:塔克拉玛干 更新时间:2023-11-03 03:51:45 26 4
gpt4 key购买 nike

它正在输出到控制台。logger.info("你好,世界信息。");//工作得很好...

但是以下代码返回“无法找到资源”错误:

Logger logger = LoggerFactory.getLogger("framework.Utilities._Test");
LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
StatusPrinter.print(lc);

我正在使用以下 XML:

<configuration>
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
<file>C:\Reports\logBack.log</file>
<!-- encoders are assigned by default the type
ch.qos.logback.classic.encoder.PatternLayoutEncoder -->
<encoder>
<pattern>%date %level [%thread] %logger{10} [%file:%line] %msg%n</pattern>
</encoder>
</appender>

<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%msg%n</pattern>
</encoder>
</appender>

<root level="debug">
<appender-ref ref="FILE" />
<appender-ref ref="STDOUT" />
</root>
</configuration>

我已经将它复制到我的类路径中的几个位置的根目录中 (Windows7\Environment Variables\System Variables\Path),但我仍然收到错误“找不到资源”。有任何想法吗?

最佳答案

And I've copied it into the root of several locations in my classpath

logback 有一个默认的查找配置文件的方式,文档是这样的:

Let us begin by discussing the initialization steps that logback follows to try to configure itself:

  1. Logback tries to find a file called logback.groovy in the classpath.

  2. If no such file is found, logback tries to find a file called logback-test.xml in the classpath.

  3. If no such file is found, it checks for the file logback.xml in the classpath..

  4. If neither file is found, logback configures itself automatically using the BasicConfigurator which will cause logging output to be directed to the console.

所以在您的情况下,当您在控制台中看到输出时,它可能正在加载基本配置。您可以尝试在类路径中指定路径或以编程方式执行,如 this

关于java - Logback 找不到资源 logback.xml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21831815/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com