Solved

Logger in Servlet

Posted on 2007-04-03
11
539 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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
copyEndy  challenge 15 55
changePi Challenge 15 76
java set up 1 46
github account with ecipse 1 17
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 …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

706 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

18 Experts available now in Live!

Get 1:1 Help Now