I'm using Tomcat 8.0.3 and log4j 2.0-rc1 to deploy a GWT application (servlet 2.5).
I believe I fixed the usual log configuration errors, but still nothing is logged to the console or file.
Head of my web.xml:
<listener>
<listener-class>org.apache.logging.log4j.core.web.Log4jServletContextListener</listener-class>
</listener>
<filter>
<filter-name>log4jServletFilter</filter-name>
<filter-class>org.apache.logging.log4j.core.web.Log4jServletFilter</filter-class>
</filter>
<context-param>
<param-name>log4jConfiguration</param-name>
<param-value>file:///C:/Users/name/Desktop/log4j2.xml</param-value>
</context-param>
<filter-mapping>
<filter-name>log4jServletFilter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
<dispatcher>INCLUDE</dispatcher>
<dispatcher>ERROR</dispatcher>
</filter-mapping>
This is the log4j2.xml configuration:
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="TRACE">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="[%p] %c{1}: %m%n"/>
</Console>
<File name="infoFile" fileName="${sys:catalina.home}/logs/info.log" >
<PatternLayout pattern="[%p] %c{1}: %m%n"/>
</File>
</Appenders>
<Loggers>
<Root level="info">
<Appender-Ref ref="Console"/>
<Appender-Ref ref="infoFile"/>
</Root>
</Loggers>
</Configuration>
I added both the log4j2 api and core to my Maven dependencies and I can see them exploded in WEB-INF\classes\
. I've also removed them from the skipJar
list in catalina.properties.
When the war is deployed, no errors or warnings are thrown in the localhost or catalina log. This is the localhost log:
INFO ContextListener: contextInitialized()
INFO SessionListener: contextInitialized()
INFO Log4jServletContextListener ensuring that Log4j starts up properly.
INFO Log4jServletFilter initialized.
The strange thing is that the info.log file is created, but never written to.
I'm also using Hibernate whose logs do show up in the console, could this be the problem?
Finally, this is how I'm using the logger:
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
private static final Logger LOG = LogManager.getLogger(MyClass.class.getName());
public void myMethod() {
LOG.info("Logging some message");
}
(The log4j2 config file is temporarily on my desktop because it seems that I can't use spaces in the path)