01 September, 2008

Access logging under Tomcat

Do you want to get "access.log" file under Apache Tomcat Server as well as under Apache HTTP Server? Like this:
192.168.1.1 - - [25/Aug/2008:15:08:11 +0400] "GET / HTTP/1.1" 200 82777
192.168.1.1 - - [25/Aug/2008:15:08:11 +0400] "GET /js/event-debug.js HTTP/1.1" 200 88582
192.168.1.1 - - [25/Aug/2008:15:08:11 +0400] "GET /js/history-debug.js HTTP/1.1" 200 28540
192.168.1.1 - - [25/Aug/2008:15:08:11 +0400] "GET /js/prototype.js HTTP/1.1" 200 126120
192.168.1.1 - - [25/Aug/2008:15:08:11 +0400] "GET /js/json2.js HTTP/1.1" 200 9490
192.168.1.1 - - [25/Aug/2008:15:08:12 +0400] "GET /css/app.css HTTP/1.1" 200 1937

Just insert one line into the "Engine" section of the "server.xml" file:
<Engine name="Catalina" defaultHost="localhost">
...
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="access." suffix=".log" pattern="common"/>
...
</Engine>


Also it is possible to collect and filter the set of raised files via this script:


access.sh
#!/bin/bash

cat access.log | cut -f2 -d"\"" access.log | cut -f2 -d" " | egrep -v -f ignore.txt | sort



ignore.txt
^/$
^/JSON-RPC$
^/JSON-RPC-GET\?
//Any other patterns

No comments: