anchor.diff:  :published_at: 2017-12-01
   :hp-tags: java
   :hp-image: /images/logos/slf4j.png
  +
  +I stumbled upon the term "structured logging" reading https://kartar.net/2015/12/structured-logging/[a 2015 blog post by James Turnbull].
  +It's not a new concept. 
  +I discovered Python developpers had a library dedicated to *structured logging*: http://www.structlog.org[structlog].
  +
  +In this article I will describe what can be done in Java with usual logging libraries like SLF4J et Logback.
   
   == Structured logging with SLF4J
   
  
positive.code: ----
  21:10:29.178 [Thread-1] gquintana INFO  logodissey.DemoLogger - Hello world!
  ----
  The `MDC.remove` (or `MDC.clear`) call is necessary to clean the MDC after usage and avoid leaving information for later logs.
  To avoid forgetting to do housekeeping afterwards, we can use a try-with-resource:
  [source,java]
  ----
  
negative.code: ----
  Hopefully, this kind of code won't make its way in your business code because, it is usually hidden in an interceptor like a Servlet filter, a Spring aspect. In Logback, there is a `MDCInsertingServletFilter` class which can be used as an example.
  
  
  == JSON logging with Logback contrib
  
  At this point, a log is more than simple string, 
  it's qualified with useful information: user, 
  
  
  == JSON logging with Logback Logstash layout
  