use log4j in tomcat5.5 ?????

i use log4j for my webapplication as follow:
- create log4j.properties file and put it under \web-inf\classes folder of webapplication:
log4j.rootLogger=DEBUG, A2

#log4j.appender.A1=org.apache.log4j.ConsoleAppender
#log4j.appender.A1.layout=org.apache.log4j.PatternLayout
#log4j.appender.A1.layout.ConversionPattern=%d %-5p [%t] %-17c{2} (%13F:%L) %3x - %m%n

log4j.appender.A2=org.apache.log4j.FileAppender
log4j.appender.A2.File=log4j.log
log4j.appender.A2.Append=false
log4j.appender.A2.layout=org.apache.log4j.PatternLayout
log4j.appender.A2.layout.ConversionPattern=%-5r %-5p [%t] %c{2} - %m%n

- copy log4j-1.2.8.jar file to web-inf\lib folder

- And use logging feature in my servlet:
import java.io.*;
import java.text.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import org.apache.log4j.*;

public class HelloWorldExample extends HttpServlet {
      static Logger log = Logger.getLogger(HelloWorldExample.class);      
    public void doGet(HttpServletRequest request,
                      HttpServletResponse response)
        throws IOException, ServletException
    {        
        log.debug("servlet is called");        
        response.setContentType("text/html");
        PrintWriter out = response.getWriter();
          out.println("Hello VAN");
    }
}

unfortunately, after requesting servlet i couldnt find any log4j.log file. Anybody help. What did i do wrong ?
hoaivanAsked:
Who is Participating?
 
suprapto45Commented:
Hi,

log4j.appender.A2.File=c:\tomcat\logs\log4j.log

should be log4j.appender.A2.File=c:/tomcat/logs/log4j.log in windows environment, am I right?

Regards
Dave
0
 
bloodredsunCommented:
Don't you have to specify the location when you specifiy "File" of where you want the log4J file created as an absolute path?

e.g.
....
log4j.appender.A2.File=c:\tomcat\logs\log4j.log
....
0
 
suprapto45Commented:
Hi,

What is the error message?

Regards
Dave
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

 
suprapto45Commented:
oh sorry, I did not read the question properly. Do what bloodredsun tell you. he is a great java expert.

Dave
0
 
bloodredsunCommented:
>>should be log4j.appender.A2.File=c:/tomcat/logs/log4j.log in windows environment, am I right?

absolutely Dave, else java will escape the characters as it's a backslash...Doh!
0
 
hoaivanAuthor Commented:
but i wanna put my log file in a folder of my web application. How can i set relative path for log file ?
0
 
bloodredsunCommented:
I'm not sure you can. I had this issue in the past and never found a suitable solution. For example
log4j.appender.R.File=/slashfindme.log

on a windows machine will go to the root of yuor current drive e.g. C:\slashfindme.log
0
 
suprapto45Commented:
Hi,

Thanks for the point. Well if you set it up like
log4j.appender.A2.File=\log4j.log

then you will have your log file in TOMCAT_HOME/bin though.

Regards
Dave
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.