This is an example of using clojure.tools.logging and unilog, with the added bonus of MDC (logging context) via io.clj/logging.
I wanted to have a minimal project that used these libraries to get useful (log messages with a context map) JSON logging output that I can send to Logstash.
Clone the repo, go to the resulting directory, and run lein run
.
You should see something like this in stdout
$ lein run
INFO [2016-10-13 10:39:09,119] main - {arguments=} - sensible-clojure-logging.core Running main
This output will also be written to a file output.log
, and as JSON to output-json.log
.
MDC stands for Mapped Diagnostic Context, effectively a list of key value pairs associated with a given thread-local context. You can read more about it in the relevant chapter of the Logback documentation.