This looks very close to the problem described in this thread , and I suspect that the problem is with a similar class loading. Due to the way logback loads logback.xml (more precisely, how it retrieves ClassLoader for this), it may fail when compiling its configuration file and return to the default BasicConfiguration .
Not sure how you pack your code, but a suggested workaround is to include logback.xml in the EAR lib. If you are not using EAR packaging, try identifying the class loader used to determine the location of the logback.xml file.
In the end, this can be a problem in logback. However, they did not check their tracker.
Update:. If you use military packaging, try setting up GlassFish to use child class loaders for delegation first. In sun-web.xml :
<sun-web-app> <class-loader delegate="false"/> </sun-web-app>
Strike>
Update: I checked a little on my side and ... I can not reproduce your problem. I created a project for Java EE 6 webapp that has the following structure:
$ tree sample
sample
| - pom.xml
`- src
`- main
| - java
| `- com
| `- stackoverflow
| `- q2418355
| | - SimpleEJB.java
| `- SimpleServlet.java
| - resources
| `- logback.xml
`- webapp
| - META-INF
| `- MANIFEST.MF
| - WEB-INF
| `- lib
`- index.jsp
My pom.xml looks like this:
<?xml version="1.0" encoding="UTF-8"?> <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <modelVersion>4.0.0</modelVersion> <groupId>com.stackoverflow.q2418355</groupId> <artifactId>sample</artifactId> <version>1.0-SNAPSHOT</version> <packaging>war</packaging> <name>sample Maven Webapp</name> <url>http://maven.apache.org</url> <dependencies> <dependency> <groupId>javax</groupId> <artifactId>javaee-api</artifactId> <version>6.0</version> <scope>provided</scope> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.7</version> <scope>test</scope> </dependency> <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-classic</artifactId> <version>0.9.18</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>1.5.11</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>2.0.2</version> <configuration> <source>1.6</source> <target>1.6</target> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <version>2.1-beta-1</version> <configuration> <failOnMissingWebXml>false</failOnMissingWebXml> </configuration> </plugin> </plugins> <finalName>sample</finalName> </build> </project>
Code SimpleEJB.java :
package com.stackoverflow.q2418355; import javax.ejb.Stateless; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @Stateless public class SimpleEJB { private static Logger logger = LoggerFactory.getLogger(SimpleEJB.class); public String sayHello(String name) { logger.debug(">> sayHello()"); logger.debug("<< sayHello()"); return "Hello " + name + "!!!"; } }
Code for SimpleServlet.java :
package com.stackoverflow.q2418355; import java.io.IOException; import java.io.PrintWriter; import javax.ejb.EJB; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @WebServlet(urlPatterns = { "/SimpleServlet" }) public class SimpleServlet extends HttpServlet { @EJB SimpleEJB bean; private static Logger logger = LoggerFactory.getLogger(SimpleServlet.class); @Override public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { logger.debug(">> doGet()"); PrintWriter out = response.getWriter(); out.println("<html><body>"); out.println("<h2>Serving at: " + request.getContextPath() + "</h2>"); out.println("<h2>Invoking EJB: " + bean.sayHello("Duke") + "</h2>"); out.println("</body></html>"); logger.debug("<< doGet()"); } }
Code for index.jsp :
<html> <body> <h2>Hello World!</h2> Invoke the Servlet by clicking <a href="SimpleServlet">here</a>. </body> </html>
And my logback.xml looks like this:
<configuration> <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> <layout class="ch.qos.logback.classic.PatternLayout"> <Pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</Pattern> </layout> </appender> <appender name="FILE" class="ch.qos.logback.core.FileAppender"> <File>/tmp/logs/testFile.log</File> <Append>true</Append> <layout class="ch.qos.logback.classic.PatternLayout"> <Pattern>%-4relative [%thread] %-5level %logger{35} - %msg%n</Pattern> </layout> </appender> <logger name="com.stackoverflow.q2418355" level="TRACE"/> <root level="debug"> <appender-ref ref="STDOUT" /> <appender-ref ref="FILE" /> </root> </configuration>
My logback.xml gets the correct load, and when I call the servlet, I get the following trace (taken from the log file):
10913 [http-thread-pool-8080-(1)] DEBUG com.stackoverflow.q2418355.SimpleServlet - >> doGet() 10928 [http-thread-pool-8080-(1)] DEBUG com.stackoverflow.q2418355.SimpleEJB - >> sayHello() 10928 [http-thread-pool-8080-(1)] DEBUG com.stackoverflow.q2418355.SimpleEJB - << sayHello() 10932 [http-thread-pool-8080-(1)] DEBUG com.stackoverflow.q2418355.SimpleServlet - << doGet()
I also tried with an EJB packaged in its own JAR and deployed to WEB-INF/lib and getting the same result, it just works. Can you spot any obvious difference? You may need to download a simplified version of your application (most likely it will be required for a BTW error message).
I am running GlassFish v3 under Eclipse 3.5 (with the GlassFish v3 plugin).