Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  1. Wiki Markup
    \[#Q1 Does Tomcat have built-in logging capabilities, and if so how do I use them?\]
  2. Wiki Markup
    \[#Q2 What role does commons-logging play in logging?\]
  3. Wiki Markup
    \[#Q3 What role does JULI and log4j play in logging?\]
  4. Wiki Markup
    \[#Q4 How do I configure commons-logging for use with Tomcat?\]
  5. Wiki Markup
    \[#Q5 How should I log in my own webapps?\]
  6. Wiki Markup
    \[#Q6 Where does System.out go? How do I rotate catalina.out?\]
  7. Wiki Markup
    \[#Q7 Where are the logs when running Tomcat as a Windows service?\]
  8. Wiki Markup
    \[#Q8 How do I customize the location of the tomcat logging.properties file?\]
  9. Wiki Markup
    \[#Q9 Since java.logging is the default commons-logging implementation in Tomcat, why is it not working in my Linux distribution?\]
    \\

Answers

Does Tomcat have built-in logging capabilities, and if so how do I use them?

...

Wiki Markup
You need to specify a commons-logging configuration file and, if you wish, a logging implementation that supports commons-logging. JDK 1.4 (and later) java.util.Logging and Log4j are the two most commonly used logging toolkits for Tomcat. Tomcat 5.5 and Tomcat 6.0 use java.logging as default implementation for commons-logging. So this _should_ work by default, but sometimes it doesn't (see \[#Q9\]). If you supply an external logging toolkit such as Log4J, it needs to be located in the $CATALINA_HOME/common/lib directory (for Tomcat 5.0 and earlier). Tomcat 5.5 and later uses commons-logging  while bootstrapping so some people suggest adding Log4j to the bootstrap classpath by using the scripts in $CATALINA_HOME/bin (see \[http://markmail.org/message/3sgxfol3njcfutsm Need for it to be in bootstrap classpath?\]). A better approch apparently working is:

...

On Fedora the startup script in typically located in /etc/rc.d/init.d/ and on Gentoo linux it is located in /etc/init.d/. On RedHat the startup script for Tomcat 5.5 is /etc/init.d/tomcat5 but eventually the real startup script is /usr/bin/dtomcat5.

Since java.logging is the default commons-logging implementation in Tomcat, why is it not working in my Linux distribution?

Yes, if you read Tomcat logging documentation, it says java.util.logging should work by default. But many Linux distribution repackage Tomcat and sometimes it does NOT work by default.

Here are some things you can check:

  1. tomcat-juli.jar should be in your $CATALINA_HOME/bin directory
  2. tomcat startup script should run java with -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
  3. tomcat startup script should run java with -Djava.util.logging.config.file=<some_path>/logging.properties
  4. obviously, the logging.properties file must exist in the directory specified in the tomcat script at point #3

Wiki Markup
If you don't know where to look for your Tomcat startup script, see the previous \[#Q8 How do I customize the location of the tomcat logging.properties file?\]

In RHEL5 (RedHat Enterprise Server 5) the Tomcat 5.5 rpm installation does not include the tomcat-juli.jar file. This is what I made:

  • look for what Tomcat version you got installed with: yum list installed tomcat5

Since I had the 5.5.23, I downloaded the Tomcat Binaries 5.5.23 from http://archive.apache.org/dist/tomcat/, then:

  • tar xf apache-tomcat-5.5.23.tar.gz
  • cd apache-tomcat-5.5.23/bin
  • cp tomcat-juli.jar /usr/share/tomcat5/bin/

Restart Tomcat... and it's working!