Hi Lee,

A couple of thoughts ...

1.) I wonder if the version of log4j you are installing into
'server/lib' is conflicting with another version of log4j in your
CLASSPATH in some way.  Have you tried placing a log4.properties file
into your webapp's 'WEB-INF/classes' directory but NOT placing log4j.jar
into 'WEB-INF/lib' or 'server/lib'?  The point of this is to test if you
are picking up log4j from some other place in your CLASSPATH.  

2.) Another thought that occurs to me is the version of commons-logging
you are using might have been compiled against a different version of
the log4j.jar than you are attempting to provide.  

As an aside, I assume you are doing something like this in the code that
you want logging in:

    package test;

    import org.apache.commons.logging.Log;
    import org.apache.commons.logging.LogFactory;
    ...
    public class MyClass {
        protected final static Log log =
LogFactory.getLog(MyClass.class);
        public void sayHi() {
            log.debug("hi");
        }
    }

Here's a trimmed down version of a log4j.properties file for you that I
use with Struts.  The log4j.logger.test that is included is for this
example MyClass I provided above to allow DEBUG level logging for it.

[log4j.properties]
log4j.rootLogger=CONSOLE

## LOGGERS ######################################################
log4j.logger.test=DEBUG
log4j.logger.net.sf.hibernate=WARN

log4j.logger.org.apache.commons.beanutils=WARN
log4j.logger.org.apache.commons.digester=WARN
log4j.logger.org.apache.commons.validator=WARN
log4j.logger.org.apache.struts=WARN

## APPENDERS ####################################################

# Empty appender for the root category
log4j.appender.EMPTY=org.apache.log4j.varia.NullAppender

log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern=%d{ISO8601} %-5p (%x) -
%m%n

--
Jonathan Rippy


-----Original Message-----
From: Lee Haslup [mailto:[EMAIL PROTECTED] 
Sent: Friday, June 25, 2004 2:22 PM
To: [EMAIL PROTECTED]
Subject: [Juglist] Logging in Struts w/ Tomcat 5


I'm building a web application using Java 1.4.2, Struts 1.1 and Tomcat 
5.0.16 and I seem to be having a bit of a struggle with logging.  I 
wonder of anyone has had experience with that combination and could give

me a clue.

Let me start by admitting that I don't know what I am talking about.  
This is more of a complaint than a confession since I am reasonably 
bright and have spent quite a bit of effort trying to figure it all out.


If I am careful not to configure anything then the commons-logging 
classes seem to find the logger the server is using and hook me up.  I 
can log "info"s and "errors" which appear on the console and in the 
Tomcat log.  "Debug" log entries are ignored because they are below the 
servers criterion.  This is good enough for my code and, if I could 
figure out how to set the debug level for my loggers I would probably be

happy. 

There are a number of ways in Struts to set the debug level (on the 
controller in the struts-config, for one) but, on close reading they 
appear to be deprecated in favor of configuring the underlying logging 
implementation. 

I've used Log4J in the past so that sounded ok but I seem to be having 
class loader problems with Tomcat when I try.  When I attempt to do my 
own logging (putting the log4j jar file in my WEB-INF/lib directory and 
log4j.properties in my classpath) Tomcat throws an error -- 
LogConfigurationException: No suitable Log constructor.  A bit of 
Googling suggested that most people with this problem move the log4j jar

to the server/lib directory (presumably so that all of the logging 
classes will be in the servers class loader.)  This is unappealing to me

since it means that I can only control logging of my webapp on machines 
where I have access to the server.  On machines where I can only deploy 
via a WAR file I can't set the debug level. 

I'm sure I am barking up the wrong tree here.  I really hadn't planned 
to spend a lot of time getting the logging to work.  As things stand 
right now I am definitely hearing the siren song of
System.out.println().

Lee


_______________________________________________
Juglist mailing list
[EMAIL PROTECTED] http://trijug.org/mailman/listinfo/juglist_trijug.org

_______________________________________________
Juglist mailing list
[EMAIL PROTECTED]
http://trijug.org/mailman/listinfo/juglist_trijug.org

Reply via email to