Community contributed extensions

AccessLog

Version History

1.1

1.0

Description

A Play framework module that performs request logging similar to an access log file in nginx or apache.

Getting started

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.

Log File Format

The log gets populated with the following format.

vhost remoteAddress - requestUser [time] "requestUrl" status bytes "referrer" "userAgent" requestTime "POST"

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.

Configuration

File path

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

Log 2 Play

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

POST variables

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

Limitations

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