1.2
- checks for a null request and/or response. It seems this can occur when jobs with OnApplicationStart are configured and production mode is used.
1.1
- creates
accesslog.path
if it doesn’t already exist.
1.0
- Initial release.
A Play framework module that performs request logging similar to an access log file in nginx or apache.
No extra installation is required besides what is described at http://www.playframework.org/modules/accesslog
This modules only relies on application.conf
configuration values and requires no code changes to your current application. However the default values are a safe bet to get you started out of the box.
The log gets populated with the following format.
vhost remoteAddress - requestUser [time] "requestUrl" status bytes "referrer" "userAgent" requestTime "POST"
- vhost: The requested virtual host
- remoteAddress: IP address of the client, ensure to pass that along if you are behind a reverse proxy
- requestUser: Userid of the person requesting the document as determined by HTTP authentication
- time: The server time the request was received
- requestUrl: The actual requested URL from the client
- status: Status of the response
- bytes: Size of the response in bytes
- referrer: The HTTP referrer request header
- userAgent: The User-Agent HTTP request header
- requestTime: Time it took for Play to process the request, in milliseconds
- POST: Body of post request, if configured
It seems as though the Response.current() is only valid when the request is handled by a controller. Serving static files, static file 404’s and 500’s etc don’t populate the same Response.current(). This prevents us from getting the bytes sent and response status code all of the time.
You can set the path of the access log file. If the path is not absolute the applicationPath is pre-appended. If the path doesn’t exist it will try to create it. Defaults to “logs/access.log”.
accesslog.path=logs/myAccessLog.txt
accesslog.path=c:/logs/myAccessLog.txt
#simply use “/” on windows, or you need to escape “\” like c:\\logs\\myAccessLog.txt
Should we also log this to the play.Logger for convenience when dev’ing so the requests are seen in the console? This is done at the INFO level. Defaults to false.
accesslog.log2play=true
Should we log POST parameters? If true, then they will get tacked on the end of the line. Defaults to false.
GET parameters will naturally get logged with the requested url.
accesslog.logpost=true
I don’t really expect this to be used for any site long term. I think it is best used to help during dev or for a quick short term solution in other environments.
For a longer term more feature rich solution you should use a reverse proxy like nginx and use its logging capabilities as described here: nginx HttpLogModule