This plugin allows you to use Logback's very flexible access framework within Play.
To use it, add the dependency:
"org.databrary" %% "play-logback-access" % "0.2"
This requires play 2.3 on scala 2.11. If you're using play 2.2 or scala 2.10, you can use version "0.1" instead.
Add org.databrary.LogbackAccessPlugin
to your conf/play.plugins
, and load the plugin somewhere with:
val accessLogger = play.api.Play.current.plugin[org.databrary.LogbackAccessPlugin].map(_.api)
Add a configuration file to your conf/application.conf
with something like:
logbackaccess.config.resource=logback-access.xml
conf/logback-access.xml
:
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%t %D %s %h %b %A "%r" "%i{Referer}" "%i{User-Agent}"</pattern>
</encoder>
</appender>
<appender-ref ref="STDOUT" />
</configuration>
(You can alternatively use logbackaccess.config.file
or logbackaccess.config.url
.)
You can read more about the supported patterns. Note that patterns requiring access to the full request body or response body (including content-length) do not currently provide useful data.
There is also a logbackaccess.context
setting if you want it to use an execution context other than the default one.
Finally, either use accessLogger.filter
in your GlobalSettings object or selectively call accessLogger.log
.