You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by Scott Burns <sb...@trcinc.com> on 2003/07/04 14:09:17 UTC

initializing log4j in jsp pages

We have been using log4j (1.2.4) in our web applications on the backend.
We are trying to use the jakarta-taglibs-log-1.0 in our presentation
layer and have a question regarding the initialization of log4j.
According to the notes from the taglibs-log.tld listed below I can drop
a config file in the WEB-INF/classes dir and do not need to explicitly
initialize log4j.  Well this works on my local setup if I have a simple
webapp with only jsps.  When I try and use this approach with existing
apps that have log4j in the backend java classes( no http) it does not
work.  I see nothing in catalina.out at startup or afterwards either.
Why would be a conflict since my original logging class will not get
initialized until I make a request and it does some backend work.  Any
suggestions?  thanks
 
Scott
 
 
The Log library allows you to embed logging calls in your JSP which can
be output to a variety of destinations thanks to the power of the log4j
project.  Initializing log4j by default these log tags do not explicitly
initialize log4j, you are free to do that however you wish.   A common
approach is to create a log4j servlet and for it to initialize log4j
using some configuration file or options specified in your web.xml My
own personal preference is just to put a log4j.properties file in the
WEB-INF/classes directory and for that to have your log4j configuration.
Then without any special servlets or initialization code log4j will
correctly initialize itself. This approach also avoids a single web app
accidentally initializing log4j several times (e.g. via 2 different
servlets).  If you have any further questions regarding the
configuration of log4j please visit the log4j site or a log4j specific
mailing list.