logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Aron Bock" <aronb...@hotmail.com>
Subject Multiple Projects Using Same Logger
Date Sat, 21 May 2005 16:48:59 GMT

I'm a new log4j user.  I want to use it in a j2ee web application--however, 
I want its components, packed in separate jars, to use the same logger(s), 
if possible.  My configuration is shown below:

j2ee web app
                log4jInitServlet (uses log4j props file)
                com.foo/ (classes in this package use logger)

So far so good.  I'm able to initialize a logger, and to log from any of the 
classes in "classes/".

Now, I want to use this already-initialized logger to log from classes 
deployed in jar files in WEB-INF/lib/ .  Is this possible?  Thus far my 
attempts have been unsuccessful.

For example, I have a separate java project, whose classes reside in package 
"com.bar", and which have been jar-ed and placed in WEB-INF/lib.  One of 
those classes is something like this:

package com.bar;

import org.apache.log4j.*;

class Bar {
    static Logger logger = Logger.getLogger(Bar.class.getName());

    public void getBar() {
        logMessage( "called getBar", Level.INFO);

    private void logMessage(String msg, Level lvl) {
        if ( logger != null && logger.getAllAppenders().hasMoreElements() )
            logger.log(lvl, msg);
            System.out.println("sysout:" + msg + " : " + lvl.toString());

The idea is that Bar provides some functionality to the webapp, and I want 
calls to it logged.  Again, though, I'd like Bar's logging to use the same 
logger(s) already-initialised by the webapp.  My props file is as below:

log4j.rootLogger=ERROR, A1

# Set levels

However, all log output from bar says "sysout", meaning it isn't using the 
logger.  I suspect this may be classloader related, but am unsure.

Would somebody enlighten me, please?

(I did search the web, and will continue to do so -- but have not yet come 
across anything germane.)



Express yourself instantly with MSN Messenger! Download today - it's FREE! 

To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org

View raw message