12 factor ring logging middleware
Make your deps.edn look like this:
coast-framework/logger {:mvn/version "1.0.0"}
Require it like this
(ns your-project
(:require [logger.core :as logger]))
Log stuff like this, returns a string
(logger/line "Request started" {"request-method" "GET" "uri" "/"})
; => "[timestamp] Request started request-method=GET" uri=/
(logger/line "Request finished" {"status" 200 "content-type" "text/plain"})
; => "[timestamp] Request finished status=200 content-type=text/plain"
Use the middleware like this
(def app (-> (your-ring-app)
(logger/logger)))
This calls println
twice and logs two ring request/response lines that look like this:
[timestamp] Request started request-method=GET route=home/index uri=/
[timestamp] Request finished status=200 duration=10ms content-type=text/html
Note route is only logged if there is a :route
keyword in the request map
cd logger && make test
MIT
Create an issue, star it or make a pull request.