-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Chuck,

On 4/2/2009 3:03 PM, Caldarale, Charles R wrote:
>> From: Dan Armbrust [mailto:daniel.armbrust.l...@gmail.com]
>> Subject: Re: How to debug Error: listenerStart?
>>
>> my webapp dynamically configures log4j with a pattern like this:
>>
>> LogManager.resetConfiguration();
>> PropertyConfigurator.configure(properties);
> 
> I think that's too late - the logger needs to be ready first thing so that 
> webapp-related log entries can be created during deployment.

In my webapp, I have a <listener> defined first that does this:

public class Log4jListener
    implements ServletContextListener
{
    private Logger logger;

    public void contextInitialized(ServletContextEvent e)
    {
        // Trigger loading of the log4j.properties file from the classpath.
        new PropertyConfigurator();

        logger = Logger.getLogger(this.getClass());

        logger.info("Log4j initialized");
    }

    public void contextDestroyed(ServletContextEvent e)
    {
        if(LogManager.class.getClassLoader()
           .equals(this.getClass().getClassLoader()))
        {
            logger.info("Log4j was loaded by application classloader;
shutting down.");

            LogManager.shutdown();
        }
        else
        {
            logger.info("Log4j was loaded by some other ClassLoader; not
shutting down.");
        }
    }
}

This appears to load my configuration correctly, but I don't see any
Tomcat messages in my log4j.log file. It's possible that Tomcat doesn't
make much to say, though.

I find messages like this in catalina.out after a successful startup:

AbandonedObjectPool is used
(org.apache.tomcat.dbcp.dbcp.abandonedobjectp...@46fd13)
   LogAbandoned: true
   RemoveAbandoned: true
   RemoveAbandonedTimeout: 30

I am using a <Context>-configured DataSource, which I might have
predicted would log to the app-configured logger, but it doesn't: it
logs to stdout.

>> INFO: Deploying web application archive ap.war
>> log4j:WARN No appenders could be found for logger
>> (org.apache.commons.digester.Digester).
>> log4j:WARN Please initialize the log4j system properly.
> 
> Those are indications that usage of the logger has already commenced.

Yup, and it's probably commons-digester that triggered the configuration
of log4j.

>> What would I need to do to make log4j within my webapp 
>> have a temporary configuration which would log to the 
>> console until the point when my webapp executes it's 
>> dynamic configuration?
> 
> Create a log4j.xml or log4j.properties file in WEB-INF/classes.

+1

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAknacMkACgkQ9CaO5/Lv0PATNACfUP6cNs6hxsvpmWIF053WK/tM
M7AAnR+xzc8vD1UOBFlhvQs41y8M3I9j
=1KZj
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to