logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Duncan Smith <dsm...@deckertelecom.net>
Subject Log4j in JSP
Date Wed, 10 Dec 2003 13:39:03 GMT
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


Mime
View raw message