Hi,

Here's a mail posted by "Dr. Evil"  to the Tomcat User mailing list. I've taken the 
liberty to post the relavant content of his mail here.

****************** begin quote ******************

Download the log4j files, and copy the .jar files into
TOMCAT_HOME/libs, otherwise servlets can't find them.
First, compile a servlet called startlogging.java, in the classes
directory:
----------------------
// start logging functions
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import org.apache.log4j.PropertyConfigurator;
public class startlogging extends HttpServlet {
    public void init() throws ServletException {
        
PropertyConfigurator.configure("/usr/local/jakarta-tomcat-4.0/webapps/myapp/WEB-INF/classes/log4j.properties");
        // or wherever your properties file is
    }
}
----------------------
Then, put this in the web.xml file:
----------------------
<servlet>
<servlet-name>startlogging</servlet-name>
<servlet-class>startlogging</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
----------------------
I put it as my first servlet entry in the file.  Order is important in
that file.
Then, create the log4j.properties file, in the classes directory:
----------------------
# Set root category priority to DEBUG and its only appender to A1.
log4j.rootCategory=DEBUG, A1
# A1 is set to be a ConsoleAppender.
#log4j.appender.A1=org.apache.log4j.ConsoleAppender
log4j.appender.A1=org.apache.log4j.FileAppender
# set up the filename - change as appropriate
log4j.appender.A1.File=/tmp/test.log
# A1 uses PatternLayout.
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n
----------------------
Finally, in classes that you want to log from:
----------------------
class myclass {
    static Category cat = Category.getInstance(userinfo.class);
    public void mymethod() {
    .....
    cat.info("This is an info log entry.");
----------------------


******************end quote ******************

31/10/2001 4:57:14 AM, chenghong <[EMAIL PROTECTED]> wrote:

>
>
>
>   is there an example for me to refer how to use log4j ?
>
>   thanks




_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com


___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to