title: spring/logback - log http request body for errors only
body: <p>I am using <code>MDC</code> inside an interceptor to add http request related fields to my logging. Now, i want to log the request body along any log of level <code>error</code> or <code>fatal</code> and/or for exceptions as well. I am totally new to <code>MDC</code>, <code>spring</code> or <code>java</code> in general.</p>
  
  <p>The providers section of my <code>logback-spring.xml</code> looks currently like this:</p>
  
  <pre><code>&lt;providers&gt;
      &lt;timestamp&gt;
          &lt;!-- &lt;fieldName&gt;timestamp&lt;/fieldName&gt; --&gt;
          &lt;timeZone&gt;UTC&lt;/timeZone&gt;
      &lt;/timestamp&gt;
      &lt;version/&gt;
      &lt;nestedField&gt;
          &lt;fieldName&gt;log&lt;/fieldName&gt;
          &lt;providers&gt;
              &lt;logLevel /&gt;
          &lt;/providers&gt;
      &lt;/nestedField&gt;
      &lt;message/&gt;
      &lt;loggerName/&gt;
      &lt;threadName/&gt;
      &lt;context/&gt;
      &lt;pattern&gt;
          &lt;omitEmptyFields&gt;true&lt;/omitEmptyFields&gt;
          &lt;pattern&gt;
              {
                  "trace": {
                      "id": "%mdc{X-B3-TraceId}",
                      "span_id": "%mdc{X-B3-SpanId}",
                      "parent_span_id": "%mdc{X-B3-ParentSpanId}",
                      "exportable": "%mdc{X-Span-Export}"
                  }
              }
          &lt;/pattern&gt;
      &lt;/pattern&gt;
      &lt;mdc&gt;
          &lt;excludeMdcKeyName&gt;traceId&lt;/excludeMdcKeyName&gt;
          &lt;excludeMdcKeyName&gt;spanId&lt;/excludeMdcKeyName&gt;
          &lt;excludeMdcKeyName&gt;parentId&lt;/excludeMdcKeyName&gt;
          &lt;excludeMdcKeyName&gt;spanExportable&lt;/excludeMdcKeyName&gt;
          &lt;excludeMdcKeyName&gt;X-RequestId&lt;/excludeMdcKeyName&gt;
          &lt;excludeMdcKeyName&gt;X-B3-TraceId&lt;/excludeMdcKeyName&gt;
          &lt;excludeMdcKeyName&gt;X-B3-SpanId&lt;/excludeMdcKeyName&gt;
          &lt;excludeMdcKeyName&gt;X-B3-ParentSpanId&lt;/excludeMdcKeyName&gt;
          &lt;excludeMdcKeyName&gt;X-B3-Sampled&lt;/excludeMdcKeyName&gt;
          &lt;excludeMdcKeyName&gt;X-B3-Flags&lt;/excludeMdcKeyName&gt;
          &lt;excludeMdcKeyName&gt;B3&lt;/excludeMdcKeyName&gt;
          &lt;excludeMdcKeyName&gt;X-Span-Export&lt;/excludeMdcKeyName&gt;
      &lt;/mdc&gt;
      &lt;stackTrace/&gt;
  &lt;/providers&gt;
  ```
  </code></pre>