Adding a RequestLogHandler to a jetty Server created from Unfiltered

43 views
Skip to first unread message

Ben Hutchison

unread,
Sep 10, 2014, 9:27:33 PM9/10/14
to unfilter...@googlegroups.com
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)
      server.addConnector(binding.connector)
    val contextHandlers = new ContextHandlerCollection
    for (adder <- contextAdders.reverseIterator)
      adder.addToParent(contextHandlers)
    server.setHandler(contextHandlers)
    server
  }

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

Ben Hutchison

unread,
Oct 26, 2014, 6:24:17 PM10/26/14
to unfilter...@googlegroups.com
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` [https://github.com/unfiltered/unfiltered/blob/0.8.3/jetty/src/main/scala/Server.scala#L10] 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?

-Ben
Reply all
Reply to author
Forward
0 new messages