即使存在,logback也找不到logback.xml(在类路径上) [英] Logback can't find logback.xml even though it exists (on the classpath)

查看:1047
本文介绍了即使存在,logback也找不到logback.xml(在类路径上)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在登录时遇到问题.我进行了设置(使用Maven),除了Logback报告找不到配置文件(但我能够使用默认的记录器配置登录到控制台)之外,其他一切似乎都很好.

I've an issue with logback. I set it up (using maven) and everything seems fine except that Logback reports it can't find the configuration file (but I'm able to log to the console using the default logger configuration).

[#| 2013-07-03T07:55:30.843 + 0200 | INFO | glassfish3.1.2 | javax.enterprise.system.std.com.sun.enterprise.server.logging | _ThreadID = 124; _ThreadName = Thread- 2; | 07:54:39,844 | -ch.qos.logback.classic.LoggerContext中的信息[默认]-找不到资源[logback.groovy]

[#|2013-07-03T07:55:30.843+0200|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=124;_ThreadName=Thread-2;|07:54:39,844 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback.groovy]

07:54:39,844 | -ch.qos.logback.classic.LoggerContext中的信息[默认]-找不到资源[logback-test.xml]

07:54:39,844 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback-test.xml]

07:54:39,844 | -ch.qos.logback.classic.LoggerContext中的信息[默认]-找不到资源[logback.xml]

07:54:39,844 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback.xml]

07:54:39,847 | -INFO [default]-设置默认配置. |#]

07:54:39,847 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Setting up default configuration. |#]

我将配置文件(称为logback.xml)放入Maven工件(这是WAR)的src/main/resources文件夹中. 有趣的是,如果我尝试从类路径中加载配置,我会成功:

I put the configuration file (called logback.xml) into the src/main/resources folder of my Maven artifact (which is a WAR). Interestingly, if I attempt to load the config from the classpath, I succeed:

Reader r = new InputStreamReader(getClass().getClassLoader().getResourceAsStream("logback.xml"));
StringWriter sw = new StringWriter();
char[] buffer = new char[1024];
for (int n; (n = r.read(buffer)) != -1; )
    sw.write(buffer, 0, n);
String str = sw.toString();
System.out.println(str);

哪个会打印我的示例配置文件:

Which prints my sample configuration file:

[#|2013-07-03T07:55:30.844+0200|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=124;_ThreadName=Thread-2;|<configuration>
    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <!-- encoders are assigned the type
             ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
        <encoder>
            <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
        </encoder>
    </appender>

    <root level="debug">
        <appender-ref ref="STDOUT" />
    </root> </configuration>|#]

我的pom.xml具有以下条目:

        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
            <version>1.0.13</version>
        </dependency>

        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-core</artifactId>
            <version>1.0.13</version>
        </dependency>

        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.7.5</version>
        </dependency>

哪些文件打包为WAR文件(在EAR文件内部). WAR文件中logback.xml的位置如下:WEB-INF/classes/logback.xml

Which is packed as a WAR file (inside an EAR file). The location of the logback.xml inside the WAR file is as follows: WEB-INF/classes/logback.xml

有人知道我的设置有什么问题吗?

Does anybody have an idea what's wrong with my setup?

非常感谢您的帮助

愚蠢的羊

推荐答案

WAR文件中的位置是正确的WEB-INF/classes.

The location within the WAR file is correct, WEB-INF/classes.

logback配置文档讨论了logback.xml文件的位置.在战争中,但是它没有提及任何关于EAR的事情.

The logback configuration documentation talks about where the logback.xml file can be located within a war, but it doesn't mention anything about an EAR.

能否请您尝试使用此链接中的信息?我想知道是否需要以特定方式将其包装到EAR中.

Could you please try the information at this link? I am wondering if it needs to be packed into the EAR in a specific way.

  1. Glassfish 3 + ear + logback.xml

(第二个链接已删除,不起作用)

(edit: second link removed, didn't work)

这篇关于即使存在,logback也找不到logback.xml(在类路径上)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆