All,

I have been trying all day to get Tomcat and Log4J to cooperate. I have
looked through many posts to this mailing list but have been unable to find
any extra information that helps me.

I am running Tomcat 4.1.27 on a Windows 2000 machine. My web app has
log4j-1.2.8.jar in its WEB-INF/lib directory. I have a config file called
log4j.xml in my WEB-INF directory. To load the configuration, I have a
ContextStartupListener implementation with this code in it:

        //first things first - initialise the logging sub-system
        try {
                System.out.println("Initialising Log4J . . .");
                String configFile =
WebAppContext.getContextParameter("log4j-config-file");
                        
                //provide default
                if ((configFile == null) || ("".equals(configFile.trim())))
{
                        configFile = "/WEB-INF/log4j.xml";
                }
                        
                String filename =
getServletContext().getRealPath(configFile);
                        
                DOMConfigurator.configure(filename);
                System.out.println(". . . done");
        } catch (Throwable t) {
                System.err.println("Exception occurred: " + t);
                t.printStackTrace(new PrintWriter(System.err));
        }
                
        //now create the log
        log =
org.apache.commons.logging.LogFactory.getFactory().getInstance(StartupListen
er.class);

        log.trace("trace enabled");
        log.debug("debug enabled");
        log.info("info enabled");
        log.warn("warn enabled");
        log.error("error enabled");
        log.fatal("fatal enabled");

My log4j.xml file is defined as:

        <?xml version="1.0"?>
        <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">

        <log4j:configuration debug="false"
xmlns:log4j="http://jakarta.apache.org/log4j/";>
                <appender name="custom"
class="org.apache.log4j.DailyRollingFileAppender">
                        <param name="File"
value="${CATALINA_HOME}/logs/custom.log"/>
                        <param name="DatePattern" value="'.'yyyy-MM-dd"/>
                
                        <layout class="org.apache.log4j.PatternLayout">
                                <param name="ConversionPattern" value="%d
%-5p [%c] %m%n"/>
                        </layout>
                </appender>
        
                <root>
                        <level value="debug"/>
                        <appender-ref ref="custom"/>
                </root>
        </log4j:configuration>

As you can see, I have tried to redirect all logging for my webapp to a
custom log file. If I set the log4j.debug system property to true, I can see
that Log4J is successfully finding and using my configuration file. Indeed,
the custom.log file is created. However, none of my log statements are
directed to this file. Instead, they go straight to the console as per
usual. Also, the debug level is the same as usual (ie. level is info instead
of debug as specified in config file).

What's really interesting is that there is some output in custom.log.
However, this output belongs to JBoss client classes (my application
utilises JBoss as an app server). Note that I am running Tomcat standalone -
not as part of a JBoss installation. Here is a sample from custom.log:

        2003-12-17 14:54:13,653 DEBUG
[org.jboss.mq.referenceable.SpyConnectionFactoryObjectFactory] Extracting
SpyConnectionFactory from reference
        2003-12-17 14:54:13,914 DEBUG
[org.jboss.mq.referenceable.SpyConnectionFactoryObjectFactory] The
GenericConnectionFactory is:
GenericConnectionFactory:[EMAIL PROTECTED],conne
ctionProperties={UIL_ADDRESS_KEY=203.8.163.174, PingPeriod=0,
UIL_PORT_KEY=8096, ClientILService=org.jboss.mq.il.uil.UILClientILService,
UIL_TCPNODELAY_KEY=yes}]
        2003-12-17 14:54:13,974 DEBUG [org.jboss.mq.Connection] Setting the
clockDaemon's thread factory
        2003-12-17 14:54:14,024 DEBUG
[org.jboss.mq.GenericConnectionFactory] Handing out ClientIL:
org.jboss.mq.il.uil.UILClientILService
        2003-12-17 14:54:14,024 DEBUG
[org.jboss.mq.il.uil.UILClientILService] UILClientILService.run()
        2003-12-17 14:54:14,134 DEBUG
[org.jboss.mq.referenceable.SpyDestinationObjectFactory]
SpyDestinationObjectFactory->getObjectInstance()

It seems Log4J is being used for JBoss client classes but not for my own.
What am I doing wrong here? I have also checked to ensure that
${CATALINA_HOME}/common/lib does not contain any logging-related JARs except
for commons-logging-api.jar. Similarly, I have made sure that my web app
does not contain any logging-related JARs except for log4j-1.2.8.jar.

Sorry for the long post and thanks for even reading this far. I'd appreciate
any help anyone can offer.

Thanks,
Kent

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to