tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jacob Kjome <>
Subject Re[2]: Log4J and tomcat
Date Thu, 13 Feb 2003 19:39:59 GMT
Hello Sloan,

You can remove the log4j.dtd.  Note that in the latest 1.2 CVS, this is
fixed.  However, there has been talk that in the 1.3 version of log4j,
the dtd might be removed for the same reason that it isn't used in
Tomcat's server.xml; because the markup is too rich and dynamic to be
described in a dtd or schema.

Also, if you use commons-logging, you should put log4j.jar in
common/lib.  It will find it there.  However, I would forgo
commons-logging altogether and just use Log4j.  BTW, how do you expect
to change the logging config without redeployment when log4j is
outside the webapp's WEB-INF/lib without shutting down Tomcat?  I'd
say that is worse than redeployment.

There are a couple solutions here.  Use Tomcat's install/uninstall
features so that you can start/stop the app in a snap, thus, allowing
you to change debug levels.  Also, look at configureAndWatch() which
will re-read your properties or xml file at a given interval without
shutting down your app or the server.  However, you can only add
loggers, not take them away.  There will be a better solution for this
in 1.3 with the WatchDog classes.

Also, you can use a custom repository selector if you want your app to
have its own logging context even when log4j is in a shared

There is an implementation of this in the new Log4j sandbox.

Plus, here is a log4j context initializer for use under Tomcat:

I know they work because I wrote them.


Thursday, February 13, 2003, 12:29:29 PM, you wrote:

SS> This is what I have defined at the beginning (could be causing the problem?)

SS>     private static final Log log = LogFactory.getLog(Initializer.class);

SS> The log factory is the org.apache.commons.logging.LogFactory.

SS> This is what I have in a servlet that gets preloaded...

SS>   String log4jFile = _config.getInitParameter("LOG4J_FILE");
SS>   if (log4jFile == null) throw new ServletException("Parameter LOG4J cannot
SS> be null");
SS>   DOMConfigurator.configureAndWatch(log4jFile);
SS>"Log configured");

SS> You would think that would do it but the line gets sent to Tomcat's
SS> console screen and not to the file that I have defined...

SS> I do not have the log4j file in my war because I want to be able to
SS> dynamically change the log msg levels without having to re-deploy...

SS> I also had trouble with Tomcat not finding the log4j.dtd in the log4j
SS> jar....  I had to extract it from the jar and put it somewhere...

SS> ----- Original Message -----
SS> From: "Ron Day" <>
SS> To: "Tomcat Users List" <>
SS> Sent: Thursday, February 13, 2003 1:15 PM
SS> Subject: RE: Log4J and tomcat

>> Try putting log4j.jar in your WEB-INF/lib directory, and your log4j.props
SS> in
>> your classes directory.
>> or
>> set up a servlet that loads on startup that uses the log4j method to
SS> define
>> the path to your prop file, in the init().
>> -----Original Message-----
>> From: Sloan Seaman []
>> Sent: Wednesday, February 12, 2003 3:23 PM
>> To:
>> Subject: Log4J and tomcat
>> I'm deploying a war file using tomcat and I wish to use Apache's common
>> logging api to log things (log4j behind the scenes).
>> For some reason my configuration file seems to be getting ignored but my
>> msgs are showing up in the console window for Tomcat.
>> Can someone tell me why this is happening?
>> How do I get my app to use my log4j conf file?
>> Thanks!
>> --
>> Sloan
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail:
>> For additional commands, e-mail:
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail:
>> For additional commands, e-mail:

SS> ---------------------------------------------------------------------
SS> To unsubscribe, e-mail:
SS> For additional commands, e-mail:

Best regards,

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message