Skip to content

12 factor app logging in a JSON format for your ring clojure app

License

Notifications You must be signed in to change notification settings

vane-tech/ring-json-logger

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation


Jason "Ring" Logger and his colleague at work.

ring-json-logger

Clojars Project license

This is a ring middleware to response time and other details about the requests arriving at your web server in a JSON format to stdout.

A twelve-factor app never concerns itself with routing or storage of its output stream. It should not attempt to write to or manage logfiles. Instead, each running process writes its event stream, unbuffered, to stdout.
The Twelve-Factor App: Logs

Example output:

{"method":"get","uri":"/health","query-string":"some=1&query=params","remote-addr":"172.18.0.1","duration":0,"status":200}
{"method":"post","uri":"/customers","query-string":null,"remote-addr":"172.18.0.1","duration":32,"status":500,"exception":"class java.lang.ArithmeticException","exception-message":"Divide by zero"}

Usage

(require '[ring.middleware.json-logger :refer [wrap-json-logger]])

; app-routes should be a valid ring application, e.g. routes defined with compojure
(def app (wrap-json-logger app-routes))

Please note that all query params are logged, so don't submit sensitive data like passwords, tokens, or credit card numbers in the URI. Parameters posted in the request body are not logged at the moment.

TODO

  • Filter sensitive parameters like tokens or passwords
  • Log post params
  • Config options

Licenses

Copyright © 2018 BillFront GmbH

Distributed under MIT License.