Solved

Logger in Servlet

Posted on 2007-04-03
11
542 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
 

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
DevOps Toolchain Recommendations

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

 
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
groupSum5 challenge 5 68
mapAB Challlenge 35 124
maven project error 5 48
egit plugin on eclipse 8 33
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
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…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

912 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

16 Experts available now in Live!

Get 1:1 Help Now