logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Duncan Smith <dsm...@deckertelecom.net>
Subject Re: Log4j in JSP
Date Wed, 10 Dec 2003 14:13:49 GMT
Thanks. now using  log4j.properties as you suggest and it seems to be working.

-Duncan

Allistair Crossley wrote:

> I've done this by adding the following at the top of my JSP
>
> <%
>   org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger("Application");
> %>
>
> I use a log4j.properties file in my WEB-INF/classes
>
> log4j.rootLogger=debug, A
> log4j.logger.Application=debug, ApplicationA
>
> log4j.appender.A=org.apache.log4j.RollingFileAppender
> log4j.appender.A.File=iq.log
> log4j.appender.A.MaxFileSize=100KB
> log4j.appender.A.MaxBackupIndex=1
> log4j.appender.A.layout=org.apache.log4j.PatternLayout
> log4j.appender.A.layout.ConversionPattern=%d %-5p %l : %m%n
>
> #### Application
>
> log4j.appender.ApplicationA=org.apache.log4j.RollingFileAppender
> log4j.appender.ApplicationA.File=application.log
> log4j.appender.ApplicationA.MaxFileSize=100KB
> log4j.appender.ApplicationA.MaxBackupIndex=1
> log4j.appender.ApplicationA.layout=org.apache.log4j.PatternLayout
>
> Hope this helps
>
> Allistair Crossley
> __________________________
>
> Intranet Senior Developer
> New Media Group, QAS Ltd
> Telephone: 020 7819 5343
> __________________________
>
> -----Original Message-----
> From: Duncan Smith [mailto:dsmith@deckertelecom.net]
> Sent: 10 December 2003 13:39
> To: log4j-user@jakarta.apache.org
> Subject: Log4j in JSP
>
> Am trying to use log4j in a JSP file.
>
> Have set up a properties file, made an initialisation servlet, added the
> servlet to the applications web.xml,
> but I can't get my jsp page to log anything. No errors come up, but
> nothing is logged into the file.
>
> I have listed all files below.
>
> Suggestions much appreiciated, cheers
> Duncan Smith - Decker Telecom Ltd
>
> log4j.lcf:
> #---------------------------------------------------------------------------
>
> #define our two catagories
> log4j.logger.PM.ErrLog=DEBUG, flErr
>
> #define our appenders
> log4j.appender.flErr=org.apache.log4j.FileAppender
> log4j.appender.flErr.File=c:\\test1234.log
>
> #Define Layouts
> log4j.appender.flErr.layout.layout=org.apache.log4j.SimpleLayout
> #---------------------------------------------------------------------------
>
> Logging.java:
> //---------------------------------------------------------------------------
>
> package PM;
>
> import org.apache.log4j.PropertyConfigurator;
> import javax.servlet.http.HttpServlet;
> import javax.servlet.http.HttpServletRequest;
> import javax.servlet.http.HttpServletResponse;
> import java.io.*;
>
> public class Logging extends HttpServlet {
>
>        public void init() {
>               String sPrefix = getServletContext().getRealPath("/");
>               String sFile = getInitParameter("log4j-init-file");
>
>               PropertyConfigurator.configure(sPrefix + sFile);
>
>        }
>
>        public void doGet(HttpServletRequest req, HttpServletResponse
> res) {
>        }
>
> }
> //---------------------------------------------------------------------------
>
> Addition to web.xml:
> <servlet>
>              <servlet-name>log4j-init</servlet-name>
>              <servlet-class>PM.Logging</servlet-class>
>
>              <init-param>
>                          <param-name>log4j-init-file</param-name>
>
> <param-value>WEB-INF/classes/log4j.lcf</param-value>
>              </init-param>
>              <load-on-startup>1</load-on-startup>
>     </servlet>
>
> Test.jsp:
> <%@ page import="java.text.*,java.util.*,java.io.*" %>
> <%@ page import="org.apache.log4j.Logger" %>
>
> <%
>  Logger lgErr = Logger.getLogger("com.ErrLog");
>
>  lgErr.info("hello");
>  lgErr.error("hello");
>  lgErr.fatal("hello");
> %>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: log4j-user-help@jakarta.apache.org
>
> <FONT SIZE=1 FACE="VERDANA,ARIAL" COLOR=BLUE>
> -------------------------------------------------------
> QAS Ltd.
> Developers of QuickAddress Software
> <a href="http://www.qas.com">www.qas.com</a>
> Registered in England: No 2582055
> Registered in Australia: No 082 851 474
> -------------------------------------------------------
> </FONT>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: log4j-user-help@jakarta.apache.org


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


Mime
View raw message