views:

105

answers:

1

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???

A: 

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.

JoseK
I have tried doing that but that logs lines like: 1. 192.168.40.1 - - [23/Jul/2010:09:14:13 +0500] "GET /<my-project-url>/ HTTP/1.1" 404 994 Most of all I need tomcat to log path of local file searched for and not found
sundoe
Yes - as the log shows in this case */<my-project-url>/* is logged as a 404. Try with another nonexistent URL like *wrongURL/wrong/jpg* and see it will appear as a 404 in this log with the full path.
JoseK
For a request like localhost/<project name>/files/file1.html it puts the url in the log and not the path of file it couldn't find. I need it to say: /usr/share/....../file1.html not found
sundoe
@sundoe: Tomcat always logs the URL and not the file path. see my update about a custom access log valve.
JoseK
JoseK I checked out the links in your update, class write/alteration for getting the filename seems too much work, atleast for now. I think I will post this on tomcat's mailing list or someplace like that and then update this page if I get a simpler solution.
sundoe