1
votes

I'm trying to get log4j application (webapp) logging working in a Tomcat 6 app. I have log4j-1.2.15.jar in my WEB-INF directory, log4j.dtd and log4j.xml in WEB-INF/classes.

My log4j.xml looks like:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd" >
<log4j:configuration>
<appender name="massAppender" class="org.apache.log4j.RollingFileAppender">
    <param name="maxFileSize" value="100KB" />
    <param name="maxBackupIndex" value="2" />
    <param name="File" value="${catalina.home}/logs/mass.log" />
    <layout class="org.apache.log4j.PatternLayout">
        <param name="ConversionPattern" value="%d{ABSOLUTE} %5p %c{1}: %m%n " />
    </layout>
</appender>

<category name="com.company.mass">
    <priority value="DEBUG"/>
    <appender-ref ref="massAppender"/>
</category>

<root>
     <appender-ref ref="massAppender" />
</root>

</log4j:configuration>

My servlet is in the package:

package com.company.mass;

where the logger is declared as:

private static Logger logger = Logger.getLogger(Handler.class);

and at the top of my doGet(...) method there is:

logger.error("foo");

When I deploy the app in Tomcat and go to the servlet, it works correctly. I even get a mass.log file, but nothing gets put in it. It doesn't show up in any other logs either, and there are no obvious errors. Any idea what's going on?

4
have you checked the catalina.out log?Gandalf
I do not have a catalina.out. My cataline.2009-05-27.log has the standard startup stuff in it.Mike Roberts

4 Answers

3
votes

Are you sure that log4j is actually using your log4j.xml for it's configuration, and not another file on the classpath?

Enable the system property -Dlog4j.debug to have log4j print out information about exactly which configuration file it is using.

0
votes

Not sure if you need a priority in your root logger. Try this config

<category name="com.company.mass">
    <priority value="DEBUG"/> 
    <!-- no need to specify appender again here -->
</category>

<root>
    <priority value="INFO"/> 
     <appender-ref ref="massAppender" />
</root>
0
votes

Try adding the line :

<param name="Threshold" value="ALL" />

to your massAppender config

and this line

<priority value ="debug"/>

inside your root definition

0
votes

When I've encountered this problem I was able to resolve it by adding common-logging.jar to my deployment assembly.