Solved

Logger in Servlet

Posted on 2007-04-03
11
543 Views
Last Modified: 2013-11-24
I have a Servlet in which I am using log4j.

In my servlet I have written

public class MyServlet extends HttpServlet {

static Logger logger = Logger
                  .getLogger(com.MyServlet.class);

    public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException    {

       
                  logger.debug(" Logger comment");
   }
}

Inside WEB-INF\properties directory there is log4j.properties file with the following content

log4j.rootCategory=DEBUG, dest1
log4j.appender.dest1=org.apache.log4j.FileAppender
log4j.appender.dest1.File=/logger.txt
log4j.appender.dest1.layout=org.apache.log4j.PatternLayout

But when this servlet is called I can't find anywhere the logger.txt file.
Please tell me how it'll be created.


0
Comment
Question by:ryna_s
  • 5
  • 3
  • 3
11 Comments
 
LVL 13

Expert Comment

by:kawas
ID: 18843002
the properties file belongs in WEB-INF/classes
0
 
LVL 13

Expert Comment

by:kawas
ID: 18843013
also, use the full path insteasd of /logger.txt, or the file will end up in the System.getProperty("user.dir") directory
0
 

Author Comment

by:ryna_s
ID: 18848484
>>also, use the full path insteasd of /logger.txt, or the file will end up in the System.getProperty("user.dir") directory

How to specify the full path. The path needs to be in context of tomcat.
I cannot specify something like C:\logger.txt because I don't know whether user will have a C: directory in his system or not. The logger file should be created somewhere inside the webapp which is deployed in Tomcat
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

Author Comment

by:ryna_s
ID: 18848495
>>the properties file belongs in WEB-INF/classes

Cannot put the properties file in classes, since I'll not be shipping the classes folder to the client. Instead jar file for all the classes will be shipped.
Also, properties file cannot be inside the jar file, as client will have to modify the properties file.
0
 

Author Comment

by:ryna_s
ID: 18849610
Anyone please
0
 
LVL 13

Accepted Solution

by:
kawas earned 400 total points
ID: 18850620
the path could be specified like so:
    ${catalina.home}/webapps/YOUR_APP_NAME
${catalina.home} is set when tomcat starts.

The place for the properties file is the classes folder, sorry about that.
0
 
LVL 13

Expert Comment

by:kawas
ID: 18850631
> The place for the properties file is the classes folder
You might want to try emailing the log people and asking them how you can load the file from somewhere else.
0
 
LVL 8

Expert Comment

by:thomas908
ID: 18850724
>>  ${catalina.home}/webapps/YOUR_APP_NAME

I have put it insdie classes, but its still not creating the logger file
0
 
LVL 13

Expert Comment

by:kawas
ID: 18850731
should have read ${catalina.home}/webapps/YOUR_APP_NAME/log.txt

Is that what you have?
0
 
LVL 8

Expert Comment

by:thomas908
ID: 18850738
You an try by giving java home, catalina home does not work on my system
0
 
LVL 8

Expert Comment

by:thomas908
ID: 18850743
oops,sorry the answer had already been accepted
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VB Script to add site to Java Exception List 4 74
Java Options in Zimbra Server 2 50
java jdbc batch example 8 29
jsp login check 12 28
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now