I have a problem with logback. I configured it (using maven) and everything seems fine, except that the log reports cannot find the configuration file (but I can enter 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 = threaded 2; | 07: 54: 39,844 | -INFO in ch.qos.logback.classic.LoggerContext [default] - Could not find the resource [logback.groovy]
07: 54: 39,844 | -INFO in ch.qos.logback.classic.LoggerContext [default] - Could not find resource [logback-test.xml]
07: 54: 39,844 | -INFO in ch.qos.logback.classic.LoggerContext [default] - Could not find resource [logback.xml]
07: 54: 39,847 | -INFO in ch.qos.logback.classic.LoggerContext [default] - default configuration setting. | #]
I put the configuration file (called logback.xml) in the src/main/resources folder of my Maven artifact (this is WAR). Interestingly, if I try to load the configuration from the class path, I will 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);
What prints my example 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"> <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>|#]
My pom.xml has the following data:
<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>
which is packaged as a WAR file (inside an EAR file). The location of the logback.xml file inside the WAR file is as follows: WEB-INF/classes/logback.xml
Does anyone have any idea what happened to my setup?
Many thanks for your help
stupidSheep