Adding a RequestLogHandler to a jetty Server created from Unfiltered

Skip to first unread message

Ben Hutchison

Sep 10, 2014, 9:27:33 PM9/10/14
Hi all,

Im trying to enable global request logging for a jetty server that hosts an Unfiltered service, following these instructions.

They suggest to add a RequestLogHandler to the jetty server, alongside the context handlers. I'm unsure how to do that in Unfiltered 0.8.1. The code that creates the jetty Server doesn't directly expose the root handler collection before it calls Server.setHandler(), ie in Server.scala:

  lazy val underlying = {
    val server = new org.eclipse.jetty.server.Server()
    for (binding <- portBindings.reverseIterator)
    val contextHandlers = new ContextHandlerCollection
    for (adder <- contextAdders.reverseIterator)

It seems like I need to attach in another, non-ContextHandler to the global handler. I suppose I can getHandler(), wrap it and add my logging handler, and then setHandler() again. Doesn't seem super-elegant, so I thought I'd post before pursuing this course.


Ben Hutchison

Oct 26, 2014, 6:24:17 PM10/26/14
Ok, Im working on a Pull Request for this functionality. I'd like to get some guidance from Unfiltered maintainers on how they'd prefer it to work.

There will be 3rd, optional param to `unfiltered.jetty.Server` [] describing an optional global RequestLogHandler. What i want feedback on is whether to:

(a) directly expose Jetty's class, param type `Option[RequestLogHandler]`

(b) Wrap it: ie expose an Option of a new case class whose fields are params passed to `new RequestLogHandler(...)`. Fields eg: filename, timezone, retainDays, dateFormat 

The latter seems more idiomatic to Unfiltered, but it carries the downside that changes/extensions to RequestLogHandler have to be added to the wrapper class.

Also, Any other comments & requests relating to this feature?

Reply all
Reply to author
0 new messages