tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Winifred Sanchez" <wasanc...@hotmail.com>
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:

  <servlet>
      <servlet-name>log4j-init</servlet-name>
      <description>
        Log4j Initializer.
      </description>
      <servlet-class>sample.servlets.Log4jInit</servlet-class>

      <init-param>
        <param-name>log4j-init-file</param-name>
        <param-value>WEB-INF/conf/log4j.lcf</param-value>
      </init-param>

      <load-on-startup>1</load-on-startup>
    </servlet>

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

log4j.appender.RP1=org.apache.log4j.RollingFileAppender
log4j.appender.RP1.File=/logs/mypackage.log
log4j.appender.RP1.Threshold=DEBUG

# 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.

log4j.appender.RP1.layout=org.apache.log4j.PatternLayout
log4j.appender.RP1.layout.ConversionPattern=....

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

log4j.appender.RP1.MaxFileSize=1000KB
log4j.appender.RP1.MaxBackupIndex=1


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 
/logs/mypackage.log.

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.

Winz

>From: "Abid Ali Teepo" <abid.ali.teepo@mogul.no>
>Reply-To: "Tomcat Users List" <tomcat-user@jakarta.apache.org>
>To: "Tomcat Users List" <tomcat-user@jakarta.apache.org>
>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");
>DOMConfigurator.configure(configFileResource.getFile());
>
>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 ?
>
>Abid
>
>
>-----Original Message-----
>From: Winifred Sanchez [mailto:wasanchez@hotmail.com]
>Sent: 17. juli 2003 16:18
>To: tomcat-user@jakarta.apache.org
>Subject: Re: Log4j initalized in each JSP ??
>
>
>Hi
>
>There's a sample initialization servlet in
>http://jakarta.apache.org/log4j/docs/manual.html. 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.
>
>Regards,
>Winz
>
> >From: "Abid Ali Teepo" <abid.ali.teepo@mogul.no>
> >Reply-To: "Tomcat Users List" <tomcat-user@jakarta.apache.org>
> >To: "Tomcat Users List" <tomcat-user@jakarta.apache.org>
> >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 
>working
> >good. Now i need to set up logging for the JSP's in my application, and 
>i'm
> >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: tomcat-user-unsubscribe@jakarta.apache.org
> >For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> >
>
>_________________________________________________________________
>Add photos to your messages with MSN 8. Get 2 months FREE*.
>http://join.msn.com/?page=features/featuredemail
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>

_________________________________________________________________
The new MSN 8: advanced junk mail protection and 2 months FREE* 
http://join.msn.com/?page=features/junkmail


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


Mime
View raw message