Saturday, June 16, 2012

Enable friendly access log times in Apache and JBoss


How do I enable friendly access log times in Apache and JBoss?

Hi All,

For every troubleshooter, it will be great if provided logs have well identified Time Stamps. With well mentioned time stamps, we can analyse the issues easy and come to solution within less time and comfotably.

Environment
  • JBoss Enterprise Application Platform (EAP)
    • 4.x
    • 5.x
  • Apache Web Server
The default access log timing in Apache and JBoss are in milliseconds and are not conducive to quickly identifying high access times, or for easily tracing through the flow of a request from Apache to JBoss using mod_jk for example.  One approach that has worked well in modifying the default configuration is to add a Time Taken string to the beginning of the log pattern followed by the request time in seconds, not milliseconds.
To enable the Time Taken in JBoss locate the following piece of code in $JBOSS_HOME/server/$CONFIG/deploy/$JBOSSWEB/server.xml
<!--
<Valve className="org.apache.catalina.valves.AccessLogValve"
       prefix="localhost_access_log." suffix=".log"
       pattern="common" directory="${jboss.server.home.dir}/log"
       resolveHosts="false" />
-->
and change the pattern="common" to pattern="Time Taken: %T %h %l %u %t %r %s %b"   The resulting xml, will look like
<Valve className="org.apache.catalina.valves.AccessLogValve"
       prefix="localhost_access_log." suffix=".log"
       pattern="Time Taken: %T %h %l %u %t %r %s %b" directory="${jboss.server.home.dir}/log"
       resolveHosts="false" />
 
Now, in Apache's httpd.conf, on RHEL /etc/httpd/conf/httpd.conf, change  LogFormat "%h %l %u %t \"%r\" %>s %b" common  to  LogFormat "Time Taken: %T %h %l %u %t \"%r\" %>s %b" common
After these changes, the access logs generated will be in a format that is much easier to digest at first sight.
%T logs response time in seconds. When greater precision is needed, use the %D option to log response time in microseconds.


!Hope This will Help
Kuldeep Sharma

No comments:

Post a Comment