JBoss 7.2 per-deployment logging does not work with slf4j and log4j
pbielicki Sep 24, 2013 3:47 AMAccording to JBoss documentation when you provide log4j.properties JBoss should respect such settings - https://docs.jboss.org/author/display/AS72/Logging+Configuration#LoggingConfiguration-PerdeploymentLogging
I created a simple application to reproduce the issue. Settings from log4.properties (located in WEB-INF/classes) are ignored. Basically, nothing is logged from the context listener shown below (not even System.err). When I remove log4j.properties I see the logs but settings are taken from standalone.xml - definitely not what I was expecting.
Does anyone know why it does not work? Am I missing something?
Simple app in question:
@WebListener
public class LoggingContextListener implements ServletContextListener {
@Override
public void contextInitialized(ServletContextEvent sce) {
System.err.println("Trying to log something using SLF4J-Log4J");
org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(getClass());
logger.error("Hello");
logger.warn("anybody home?");
logger.info("can you hear me?");
logger.debug("WTF?");
System.err.println("Did you notice any logs?");
}
@Override
public void contextDestroyed(ServletContextEvent sce) {
}
}
with the following log4j.properties:
log4j.rootLogger=WARN, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
and pom.xml:
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>logging-jboss</groupId>
<artifactId>logging-jboss</artifactId>
<version>1.0</version>
<name>Logging in JBoss 7.2</name>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.5</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<!-- Support Servlet 3.x and higher -->
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</build>
</project>
BTW. Logs after removing log4j.properties:
09:45:14,578 ERROR [stderr] (ServerService Thread Pool -- 54) Trying to log something using SLF4J-Log4J
09:45:14,582 ERROR [logging.LoggingContextListener] (ServerService Thread Pool -- 54) Hello
09:45:14,582 WARN [logging.LoggingContextListener] (ServerService Thread Pool -- 54) anybody home?
09:45:14,582 INFO [logging.LoggingContextListener] (ServerService Thread Pool -- 54) can you hear me?
09:45:14,582 ERROR [stderr] (ServerService Thread Pool -- 54) Did you notice any logs?
09:45:14,756 INFO [org.jboss.as.server] (ServerService Thread Pool -- 26) JBAS018559: Deployed "logging-jboss-1.0.war" (runtime-name : "logging-jboss-1.0.war")
Message was edited by: Przemyslaw Bielicki