CopyDisable

Monday, 15 August 2011

Enabling HTTP access log in Glassfish

To enable HTTP access log in Glassfish domain, login to the Admin console of the domain and go to the HTTP Service link:

Access Logging Configuration:
 

Checking the Enabled check box next to Access Logging enables HTTP access logging. Depending on the number of access requests our server receives we have to configure the log rotation. The Log Rotation policy is always time. The default value of Rotation Interval is 1440 minutes, i.e. 24 hours. So by default one access log file will be created every day. If number of HTTP requests to the server is high, then in a single day the log file will grow very large. So we have to change the Rotation Interval as per our requirement. If we reduce the Rotation Interval value from the default value of 1day, then we have to configure the Rotation Suffix also. The access log file will be rotated only if the rotation suffix of the new access log file is different from the rotation suffix of the existing access log file. Buffer Size value is used to configure the buffer size of the access logs. Write interval parameter allows you to specify the interval of writing the access log file. Last parameter is Format and it allows us to specify what information we want to capture in the access log file. The default value of Format is “%client.name% %auth-user-name% %datetime% %request% %status% %response.length%”. Following values are available for including in access log pattern:
  • %auth-user-name%
  • %client.dns%
  • %client.name%
  • %cookie.value%
  • %datetime%
  • %header.accept%
  • %header.%
  • %header.auth%
  • %header.date%
  • %header.if-mod-since%
  • %header.user-agent%
  • %header.referer%
  • %http-method%
  • %http-uri%
  • %http-version%
  • %query-str%
  • %referer%
  • %request%
  • %response.length%
  • %status%
  • %user.agent%
  • %vs.id%
Also Glassfish allows us to specify an access log pattern by its nickname instead of writing the full access log format. The allowed values are:
  • common: Apache web server’s “common” access log pattern
  • combined: Apache web server’s “combined” access log pattern.
    For details of Apache log formats you can read: http://httpd.apache.org/docs/2.0/logs.html

Now I have configured the access log to rotate in every two hours and in every 2 minutes the log file will be updated. In the Rotation Suffix field, I have added ‘T’HH-mm-ss after default value yyyy-MM-dd so that the new log files that will be generated every two hours will have a unique name. So my access log files will have name like server_access_log.2011-04-19T17-13-10.txt. For supported formats, see the link http://java.sun.com/javase/6/docs/api/java/text/SimpleDateFormat.html.



জয় আই অসম,
প্রণব শর্মা