title: Logback : using different patterns for different markers
body: <p>The software I'm working on uses MDCs for specific data (username, ip, execution time and so on). I want some logs to use a specific pattern using some MDCs, and some logs to use another pattern using other MDCs.</p>
  
  <p>I thought that markers would do the job, and I set up different markers, let say :
  PROFILE_MARKER - used for profile logs
  AUDIT_MARKER - used for audit logs</p>
  
  <p>I have 3 appenders in my logback.xml config file, one for both my markers, and one for all the other logs :</p>
  
  <pre><code>&lt;configuration&gt;
    &lt;appender name="profiler" class="ch.qos.logback.core.ConsoleAppender"&gt;
      &lt;encoder&gt;
        &lt;pattern&gt;%d [%t] [%X{USER}] [PROFILER] %-5p %m %X{TIME} ms %n&lt;/pattern&gt;
      &lt;/encoder&gt;
      &lt;filter class="ch.qos.logback.core.filter.EvaluatorFilter"&gt;
        &lt;evaluator class="ch.qos.logback.classic.boolex.OnMarkerEvaluator"&gt;
          &lt;marker&gt;PROFILER&lt;/marker&gt;
        &lt;/evaluator&gt;
        &lt;onMismatch&gt;DENY&lt;/onMismatch&gt;
        &lt;onMatch&gt;ACCEPT&lt;/onMatch&gt;
      &lt;/filter&gt;
    &lt;/appender&gt;
  
    &lt;appender name="audit" class="ch.qos.logback.core.ConsoleAppender"&gt;
      &lt;encoder&gt;
        &lt;pattern&gt;%d [%t] [%X{USER}] [AUDIT] %-5p IP=%X{IP},ID=%X{ID} %m %n&lt;/pattern&gt;
      &lt;/encoder&gt;
      &lt;filter class="ch.qos.logback.core.filter.EvaluatorFilter"&gt;
        &lt;evaluator class="ch.qos.logback.classic.boolex.OnMarkerEvaluator"&gt;
          &lt;marker&gt;AUDIT&lt;/marker&gt;
        &lt;/evaluator&gt;
        &lt;onMismatch&gt;DENY&lt;/onMismatch&gt;
        &lt;onMatch&gt;ACCEPT&lt;/onMatch&gt;
      &lt;/filter&gt;
    &lt;/appender&gt; 
  
    &lt;appender name="stdout" class="ch.qos.logback.core.ConsoleAppender"&gt;
      &lt;encoder&gt;
        &lt;pattern&gt;%d [%t] [%X{USER}] %-5p %c - %m %n&lt;/pattern&gt;
      &lt;/encoder&gt;
      &lt;filter class="ch.qos.logback.core.filter.EvaluatorFilter"&gt;
        &lt;evaluator class="ch.qos.logback.classic.boolex.OnMarkerEvaluator"&gt;
          &lt;marker&gt;AUDIT&lt;/marker&gt;
          &lt;marker&gt;PROFILE&lt;/marker&gt;
        &lt;/evaluator&gt;
        &lt;onMismatch&gt;ACCEPT&lt;/onMismatch&gt;
        &lt;onMatch&gt;DENY&lt;/onMatch&gt;
      &lt;/filter&gt;
    &lt;/appender&gt;
    &lt;root level="INFO"&gt;
      &lt;appender-ref ref="audit" /&gt;
      &lt;appender-ref ref="profiler" /&gt;
      &lt;appender-ref ref="stdout" /&gt;
    &lt;/root&gt;
  </code></pre>
  
  <p>I have the feeling I am doing this wrong, and that I should use only one appender, and maybe use filters differently. However I can't figure out how.
  Maybe markers aren't the solution here ?</p>
  
  <p>Any help would be greatly appreciated.</p>