Ceki and others - thanks in advance for your help with this question
I am looking to use log4j in a j2ee application. This question has more to do with
design patterns than log4j specifically, but I am hoping that someone will have come
across and solved something similar.
As far as I know, you need to configure a property configurator for each threads. For
the servlets, I set up a servlet that loads on startup, and sets it up as follows:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
public class StartLogging extends HttpServlet
{
static Category cat = Category.getInstance(StartLogging.class.getName());
public void init(ServletConfig config) throws ServletException
{
String log4jProps = config.getInitParameter("log4j.properties");
System.out.println("Starting Logging using properties file: " +
log4jProps);
// this is currently a hack, as the getinitParameter is not yet tested.
PropertyConfigurator.configure(log4jProps);
cat.info("StartLogging Servlet started successfully using props: " +
log4jProps);
}
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
I pass the location of the properties file as an initialisation parameter to this
servlet.
This should work for servlets and jsp's because by definition they should all run in
the same vm. (I think. If anyone can see why this wouldn't work - let me know).
However, for EJB's and my general classes - where should the
PropertyConfigurator.configure() line go? They are not guaranteed to run in the same
thread (i don't think).
I'm sure that other people must have come across this problem (if indeed it is a
problem) - what should I do?
Thanks in advance to all who answer.
Scott
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]