Servlet Logging in Tomcat

Posted on 2005-05-13
Last Modified: 2006-11-18
I want to log information about my servlet each time it is called.  I'm not sure how to set this up with Tomcat.  As best I can tell, I need to add the following element,

      <!-- Global logger unless overridden at lower levels -->
      <Logger className="org.apache.catalina.logger.FileLogger"
              prefix="servlet." suffix=".log" timestamp="true" />

somewhere in my sever.xml file.  I got this information from the following address:  If this is true, then where exactly should in place this element in server.xml?

This has me a little confused as it conflicts with the information I read at,  I believe it implies that a log file called, servlet.log, will automatically be created.

Which is true?  Is either true?  Or are they both true but different approaches?

Lastly, once I've told Tomcat about logging my servlet, will do some automatic logging of sevlet information or will have to tell it exactly what to log?  And if I tell it what to log, do I just use the following method?

httpServletRequest.getSession().getServletContext().log("Some message");

Thank you, in advance, for help on this issue.
Question by:HycelTaylor
    1 Comment
    LVL 19

    Accepted Solution

    with evolution of tomcat (and jdk) logging mechanisms in tomcat were also changing. Both links which you provided are correct, but they describe diffferent versions of tomcat.
    It is better consult in that case original documentation of tomcat vor your version.
    for tomcat 5.5:
    for tomcat 5.0:
    for tomcat 4.1

    in any case your servlet can be the same: you will use getServletContext().log() api call.
    it is only different way of configuration.

    Featured Post

    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.

    Join & Write a Comment

    Introduction As you’re probably aware the HTTP protocol offers basic / weak authentication, which in combination with the relevant configuration on your web server, provides the ability to password protect all or part of your host.  If you were not…
    Hi, in this article I'm going to teach you how to run your own site, and how to let people in (without IP). I'll talk about and explain each step... :) By the way, everything in this Tutorial is completely free and legal. This article is for …
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    755 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

    20 Experts available now in Live!

    Get 1:1 Help Now