Unable to make tomcat log basic 404 type error messages

sundoe picture sundoe · Jul 23, 2010 · Viewed 7.2k times · Source

I need the log where tomcat puts 404 type errors. I am using: tomcat 6 on Centos 5.2

I have been getting 404 errors in applications deployed on tomcat. I was unable to find the logs where tomcat puts messages when it is unable to find requested files and other simple errors. - I am not talking about stuff logged by applications, just 404 type stuff.

I checked /logs and found following types of files

  • catalina.out : contains startup and shutdown messages (mostly INFO messages)
  • catalina..log : contains same data as above file for its date
  • host-manager.year-mm-dd.log : empty (Seems to be meant for tomcat manger, I have not been using that)
  • localhost.year-mm-dd.log : some application related log message (org.apache.catalina.core.ApplicationContext... INFO messages)
  • manager.year-mm-dd.log : empty

So, none of these contain the 404 errors. Since I installed tomcat by simply unpacking it in /usr/share I'm pretty sure it has no logs in /var/log (I checked and nothing for catlina or tomcat).

I have tried, as also suggested by JoseK, to configure a valve in server.xml

<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"  
     prefix="localhost_access_log." suffix=".txt" pattern="common" resolveHosts="false"/>

This created the file /logs/localhost_access_log.txt which contains details of requests coming in e.g.

192.168.40.1 - - [23/Jul/2010:09:14:13 +0500] "GET /<project url>/files/file1.html HTTP/1.1" 404 1084

It contains request url: //files/file1.html I need the path of the file it couldn't find: /usr/share...../files/file1.html JoseK has further suggested writing a custom valve for this, but it seems like too much work for a small requirement. Does anyone know a simpler way???

Answer

JoseK picture JoseK · Jul 24, 2010

Tomcat doesn't log requests by default, but it can do if you uncomment this line in conf/server.xml:

<Valve className="org.apache.catalina.valves.AccessLogValve"
    directory="logs" prefix="localhost_access_log." suffix=".txt"
    pattern="common" resolveHosts="false"/>

This will log your 404s as well.

From the OPs comments, it looks like the solution is to write a custom AccessLogValve. Extending the Tomcat one and adding the output format desired.

See http://tomcat.apache.org/tomcat-5.5-doc/config/valve.html and http://www.devx.com/Java/Article/32730/1954 for ideas.