无法使 tomcat 记录基本 404 类型错误消息
我需要 tomcat 放置 404 类型错误的日志。 我正在使用:Centos 5.2 上的 tomcat 6
我在部署在 tomcat 上的应用程序中收到 404 错误。当 tomcat 无法找到请求的文件和其他简单错误时,我无法找到 tomcat 放置消息的日志。 - 我不是在谈论应用程序记录的内容,只是 404 类型的内容。
我检查了 /logs 并发现以下类型的文件
- catalina.out :包含启动和 关机消息(主要是 INFO 消息)
- catalina..log :包含 其日期与上述文件的数据相同
- host-manager.year-mm-dd.log :空 (好像是给tomcat manger用的, 我没有使用过)
- localhost.year-mm-dd.log :一些 应用程序相关的日志消息 (org.apache.catalina.core.ApplicationContext... INFO 消息)
- manager.year-mm-dd.log :空
因此,这些都不包含 404 错误。因为我只是通过在 /usr/share 中解压来安装 tomcat,所以我很确定它在 /var/log 中没有日志(我检查过,没有发现 catlina 或 tomcat 的日志)。
我已经尝试,正如 JoseK 所建议的那样,在 server.xml 中配置一个阀门
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log." suffix=".txt" pattern="common" resolveHosts="false"/>
这创建了文件 /logs/localhost_access_log.txt ,其中包含传入请求的详细信息,例如
192.168.40.1 - - [23/Jul/2010:09:14:13 +0500] "GET /<project url>/files/file1.html HTTP/1.1" 404 1084
它包含请求 url: //files/file1.html 我需要它找不到的文件的路径:/usr/share...../files/file1.html JoseK 进一步建议为此编写一个自定义阀门,但对于一个小需求来说,这似乎需要太多工作。有谁知道更简单的方法吗???
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???
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
默认情况下,Tomcat 不会记录请求,但如果您在
conf/server.xml
中取消注释此行,它就可以记录请求:这也会记录您的 404。
从OP的评论来看,解决方案似乎是编写一个自定义的AccessLogValve。扩展 Tomcat 并添加所需的输出格式。
请参阅 http://tomcat.apache.org/tomcat-5.5-doc /config/valve.html 和 http://www.devx.com /Java/Article/32730/1954 寻求想法。
Tomcat doesn't log requests by default, but it can do if you uncomment this line in
conf/server.xml
: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.