logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Scott Sauyet <li...@sauyet.com>
Subject App server session recovery configures log4j too early
Date Wed, 09 Jan 2008 14:57:58 GMT
I've been using log4j for years with no issue, but today I've got 
something that's stumped me.  I need to find a way to either configure 
log4j early on application server startup, or at least to reconfigure it 
on demand.

I have a custom file appender that I need to statically configure before 
the standard log4j configuration.  I do this with a simple servlet that 
runs at startup before my main application.  It sets the directory for 
the log files based on application-wide configuration, leaving only the 
file name to be set by log4j's configuration file.  This works fine...

... except that when the server restarts with live sessions, there are 
objects stored in session from a third-party library (Wicket) that hold 
references to Loggers.  As the application server (Tomcat for now) 
recreates these, log4j's initialization starts and the loggers are 
configured too early.  Because the directory hasn't been set explicitly, 
these files end up in Tomcat's root directory.  Then when my servlet 
runs, the static initialization is too late to have an effect on the 

No logging is done in the period before my initialization servlet is 
run, so I don't think the files are actually created, so if I can just 
just intervene and reset the file appenders' locations, I think I would 
be okay.  But I don't know how to do that.  Is there a straightforward 
way to get hold of all FileAppenders of my custom class?

Or is there some better way to do this altogether?  Really, the goal is 
for the user's configuration of the application to be done in a single 
file.  That include configuring the location of log files.  I think this 
could be done by running a custom Configurator, and the code doesn't 
scare me, but I still don't know how I could intercept these early calls 
to log4j to use my configurator without requiring them to add some 
system property.  The application is to be distributed as a single war 
file, and messing with System properties would be very much frowned 
upon.  But that was the only other approach I could see.

Any suggestions?


   -- Scott Sauyet

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

View raw message