/sensible-clojure-logging

A minimal example of using clojure.tools.logging, spootnik/unilog, and io.clj/logging to produce JSON log output with MDC context.

Primary LanguageClojure

sensible-clojure-logging

This is an example of using clojure.tools.logging and unilog, with the added bonus of MDC (logging context) via io.clj/logging.

Why?

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.

How do I run this example?

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.

What is MDC?

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.