tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Winifred Sanchez" <>
Subject RE: Log4j initalized in each JSP ??
Date Thu, 17 Jul 2003 17:09:07 GMT
Hi again.

The init servlet can log only for the web application where you include it 
in (supposedly). It is included in the WEB-INF/web.xml file of the webapp. 
In the sample init servlet, the log4j config file being read is in the Java 
Properties format which is why PropertyConfigurator is used. You can change 
it to DOMConfigurator if the config file is in XML. The config file to read 
can be specified in web.xml. For example, this is how I included the init 
servlet in my web.xml:

        Log4j Initializer.



The log4j-init-file is the config file that is read by log4j (for your case, 
it can be /log.xml). In WEB-INF/conf/log4j.lcf, I have:

log4j.logger.mypackage=DEBUG, RP1

# RP1 is the RollingFileAppender that outputs to a rolling log
# file


# Define a pattern layout for the file.
# For more information on conversion characters (i.e. d,p,t,c,l,m,n)
# please see the PatternLayout class of the Log4j API.


# Set the max size of the file and the number of backup files


And then for each of my servlets, I have:

private static Logger logger = Logger.getLogger(MyServlet.class.getName());

All logs for mypackage are saved to /logs/mypackage.log and assuming that 
MyServlet is under mypackage, its logs will also be saved to 

In your case, you may just need to add:

private static Logger logg = Logger.getLogger(request.getClass().getName());

to each of your jsp's.

I hope this helps.


>From: "Abid Ali Teepo" <>
>Reply-To: "Tomcat Users List" <>
>To: "Tomcat Users List" <>
>Subject: RE: Log4j initalized in each JSP ??
>Date: Thu, 17 Jul 2003 17:06:54 +0200
>Thanks for the reply
>I've read that article but it doesn't solve my problem. I want to have a 
>different logger for each webapplication. And i think that initservlet is 
>suppose to log for  all webapplications. My other problem with that init 
>servlet is why it doesn't contain the code i'm currently using in my 
>servlet e.g :
>private static Logger logg = Logger.getLogger(BidServletProxy.class);
>URL configFileResource = BidServerProxy.class.getResource("/log.xml");
>This how it's set up now in my servlet and it works fine. My question is, 
>how can i use the same logger for my jsp residing in the same webapp ?
>-----Original Message-----
>From: Winifred Sanchez []
>Sent: 17. juli 2003 16:18
>Subject: Re: Log4j initalized in each JSP ??
>There's a sample initialization servlet in
> It runs when tomcat is
>started and there is no need to initialize log4j for every servlet. I guess
>it should also work for jsps.
> >From: "Abid Ali Teepo" <>
> >Reply-To: "Tomcat Users List" <>
> >To: "Tomcat Users List" <>
> >Subject: Log4j initalized in each JSP ??
> >Date: Thu, 17 Jul 2003 14:33:06 +0200
> >
> >Hi
> >
> >I've set up some logging for my main servlet, and it appears to be 
> >good. Now i need to set up logging for the JSP's in my application, and 
> >a little bit confused .... because i don't think i should be initializing
> >and defining my logger for each jsp-page ?? That sunds a bit overkill 
> >anyone have suggestions as to how i can organize it .... and what code
> >should go in each jsp ? Maybe some pointers ?
> >
> >Regards
> >Abid
> >
> >---------------------------------------------------------------------
> >To unsubscribe, e-mail:
> >For additional commands, e-mail:
> >
>Add photos to your messages with MSN 8. Get 2 months FREE*.
>To unsubscribe, e-mail:
>For additional commands, e-mail:
>To unsubscribe, e-mail:
>For additional commands, e-mail:

The new MSN 8: advanced junk mail protection and 2 months FREE*

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

View raw message