Hi!
I'm using ring as a part of compojure, and the Jetty adapter. I'd like to log requests, and thought it would be good to take advantage of the NCSARequestLog that's built into Jetty. To do so, I made a change to ring.adapter.jetty, namely changing in ring.adapter.jetty/run-jetty
(.setHandler (proxy-handler handler))
to
(.addHandler (proxy-handler handler))
(This is the difference between ring.adapter.jetty.clj and jetty-test.adapter.jetty.clj used below.)
I have two motivations for this:
1. Jetty already has all the infrastructure for logging, including log rotation and proper formatting for NCSA logs; and
2. NCSA logs includes information about both the request and the response. By being in Jetty, it has easy access to both the request as it comes in, and the response as it goes out.
Does this seem reasonable? What other approaches are people taking to request logging or logging in general?
Thanks for any feedback!
Michael Glaesemann
grzm seespotcode net
(ns jetty-test.server
(:use [jetty-test.adapter jetty])
(:import (
java.io File)
(org.mortbay.jetty NCSARequestLog)
(org.mortbay.jetty.handler RequestLogHandler)))
(def port 8089)
(def log-directory "/Users/grzm/Desktop/lisp/clj/src/jetty-test/log")
(def log-file-name "server-yyyy_mm_dd.log")
(defn app [req]
{:status 200
:headers {"Content-Type" "text/html"}
:body "It's better than bad!" })
(defn jetty-configurator [server]
(doto server
(.addHandler (doto (RequestLogHandler.)
(.setRequestLog (NCSARequestLog.
(.getPath (File. log-directory log-file-name))))))))
(defonce server
(run-jetty #'app
{:configurator #'jetty-configurator
:port port
:join? false}))