How to enable friendly access log times in Apache, Tomcat, NGINX and JBoss?
Environment
- RedHat JBoss Enterprise Application Platform (EAP)
- 4.x
- 5.x
- 6.x
- 7.x
- Red Hat Enterprise Linux (RHEL)
- 6.x
- 7.x
- Red Hat Software Collections (RHSCL)
- 2.x
- 3.x
- Red Hat JBoss Web Server (JWS)
- 2.x
- 3.x
- Red Hat JBoss Core Services (JBCS)
- Apache HTTPD
- 2.2
- 2.4
- Apache Tomcat
- 6.x
- 7.x
- 8.x
- NGINX Web Server
- 1.8
- 1.10
- 1.12
Issue
- How to enable friendly access log times in
ApacheandJBoss? - How to enable friendly access log times in
ApacheandTomcat? - How to enable friendly access log times in NGINX?
Resolution
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.
For EAP 4.x / 5.x
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 %D %h %l %u %t %r %s %b %{COOKIE}i %{SET-COOKIE}o". The resulting xml, will look like
<Valve className="org.apache.catalina.valves.AccessLogValve"
prefix="localhost_access_log." suffix=".log"
pattern="Time Taken: %T %D %I %h %l %u %t %r %s %b %{COOKIE}i %{SET-COOKIE}o" directory="${jboss.server.home.dir}/log"
resolveHosts="false" />
For EAP 6.x
Refer How to enable access logging for JBoss EAP 6
For EAP 7.x
Refer How to enable friendly access log times in JBoss EAP7
For Apache
In Apache's httpd.conf, change from:
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %b" common
...(snip)...
CustomLog logs/access_log combined
to:
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %b" common
LogFormat "Time Taken: %T %D %h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" \"%{COOKIE}i\" \"%{SET-COOKIE}o\"" custom
...(snip)...
CustomLog logs/access_log custom
After these changes, the access logs generated will be in a format that is much easier to digest at first sight.
Note: %T logs response time in seconds. When greater precision is needed, use the %D option to log response time in microseconds.
For NGINX
Refer How to enable friendly access log times in NGINX?
For Tomcat 6.x / 7.x / 8.x
- To enable access logs in Tomcat locate the following piece of code in Tomcat
server.xmlfile.
<!--
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log." suffix=".txt" pattern="common" resolveHosts="false"/>
-->
and change the pattern="common" to pattern="Time Taken: %T %h %l %u %t %r %s %b %{COOKIE}i %{SET-COOKIE}o". The resulting xml, will look like
<Valve className="org.apache.catalina.valves.AccessLogValve"
prefix="localhost_access_log." suffix=".log"
pattern="Time Taken: %T %D %h %l %u %t %r %s %b %I %{COOKIE}i %{SET-COOKIE}o" directory="logs"
resolveHosts="false" />
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.
Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.
