• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 570
  • Last Modified:

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 ?
0
hoaivan
Asked:
hoaivan
  • 4
  • 3
2 Solutions
 
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
 
suprapto45Commented:
oh sorry, I did not read the question properly. Do what bloodredsun tell you. he is a great java expert.

Dave
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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:
>>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

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now