A ring middleware for logging requests.
You can find the latest release at Clojars.
Logging is done using clojure.tools.logging, so you can use any logging framework it supports.
The intention of the design is that you can achieve quiet prod logging, verbose debug logging, and useful levels in between by adjusting only the log config (as opposed to making code changes and reloading).
The logger used is "com.duelinmarkers.ring-request-logging", so that's the logger to reconfigure if you want more or less logging.
The public API is the wrap-request-logging
function.
(ns example
(:require
[ring.middleware.params :refer (wrap-params)]
[ring.middleware.keyword-params :refer (wrap-keyword-params)]
[com.duelinmarkers.ring-request-logging :refer (wrap-request-logging)]))
(defn ring-app [request] {:status 200 :body "Worst app ever!"})
(def logged-app
(wrap-request-logging ring-app
:param-middleware [wrap-params
wrap-keyword-params]))
On each request, this middleware will do the following:
- The start of each request will be logged at
:info
level. - The entire request map will be logged at
:trace
level. (You almost certainly only want that on for local testing.) - The supplied
:param-middleware
will be run in the provided order. - The
:params
of the request will be logged at:debug
level. - The wrapped app will be invoked.
- Anything thrown by the app will be logged at
:error
level and passed to the supplied:error-fn
. The default:error-fn
rethrows. - Assuming nothing was thrown, the end of each request will be logged at
:info
level.
The param-middleware is incorporated so that the start of request processing can be logged as early as possible, before reading the request body, but params can still be logged.
See the doc string for wrap-request-logging
for options.
See the tests for details.
Copyright © 2012 John D. Hume
Distributed under the Eclipse Public License, the same as Clojure.