HTTP Access Logs


Tomcat has support for logging, allowing you to track page-hit counts, user session activity, etc. Those logfiles are in the same format as those created by standard web servers. This allows you to use tools you may already have, to work with your web applications and to analyze how they're being used.


Tip: The standard HTTP logging format is at http://www.w3.org/Daemon/User/Config/Logging.html#common-logfile-format.

How do I do that?

To enable HTTP logging, you need to go to the deploy/jbossweb-tomcat55.sar directory. There you will see the server.xml file, to which you'll need to add the following valve definition:

     <Valve className="org.apache.catalina.valves.FastCommonAccessLogValve"            prefix="localhost_access_log." suffix=".log"            pattern="common" directory="${jboss.server.home.dir}/log"            resolveHosts="false" /> 

You'll find the valve commented out, so all you really need to do is uncomment the definition. To get this to take effect you need to restart the JBoss server. Once you've restarted the server, Tomcat will create an access log, such as localhost_access_log.2005-04-08.log, where the date in your filename will be different. This file has the HTTP server requests logged into it, and in it you will see entries such as this:

     127.0.0.1 - - [08/Apr/2005:05:21:55 -0600]     "GET /jmx-console/HtmlAdaptor? action=inspectMBean&name=jboss.system%3Aservice     %3DLogging%2Ctype%3DLog4jService HTTP/1.1" 200 10320     0:0:0:0:0:0:0:1 - - [08/Apr/2005:05:40:17 -0600]     "GET /todo/ HTTP/1.1" 401 952     0:0:0:0:0:0:0:1 - pinky [08/Apr/2005:05:40:23 -0600]     "GET /todo/ HTTP/1.1" 304 -     0:0:0:0:0:0:0:1 - pinky [08/Apr/2005:05:40:26 -0600]     "GET /todo/style.css HTTP/1.1" 304 -     0:0:0:0:0:0:0:1 - pinky [08/Apr/2005:05:40:26 -0600]     "GET /todo/front.faces HTTP/1.1" 200 11150     0:0:0:0:0:0:0:1 - pinky [08/Apr/2005:05:40:41 -0600]     "GET /todo/style.css HTTP/1.1" 304 -     0:0:0:0:0:0:0:1 - pinky [08/Apr/2005:05:40:41 -0600]     "POST /todo/front.faces HTTP/1.1" 200 1278     0:0:0:0:0:0:0:1 - pinky [08/Apr/2005:05:40:46 -0600]     "GET /todo/style.css HTTP/1.1" 304 -     0:0:0:0:0:0:0:1 - pinky [08/Apr/2005:05:40:46 -0600]     "POST /todo/task.faces HTTP/1.1" 200 1360     0:0:0:0:0:0:0:1 - pinky [08/Apr/2005:05:40:48 -0600]     "GET /todo/style.css HTTP/1.1" 304 -     0:0:0:0:0:0:0:1 - pinky [08/Apr/2005:05:40:48 -0600]     "POST /todo/task.faces HTTP/1.1" 200 11150 

What just happened?

You enabled logging for the Tomcat web server that is built into JBoss. You restarted the server to get your changes to take effect. Then you went to different areas of JBoss and possibly your test application. Finally you looked into the logfile that is specific to the HTTP requests to see what it put in there.

One thing we didn't mention is that the logging format is the standard web request logging format, so it's easy to use these logfiles with products that support that. You can find more information about the Tomcat logging configuration at http://jakarta.apache.org/tomcat/tomcat-5.5-doc/config/valve.html.



JBoss. A Developer's Notebook
JBoss: A Developers Notebook
ISBN: 0596100078
EAN: 2147483647
Year: 2003
Pages: 106

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net