title: Logback JaninoEventEvaluator to direct log events to a specific appender
body: <p>I have a logback-test xml as follows. I wanted to filter out any logs from package org.jdbcds from console and from GENERIC_LOG_FILE and have them in a seperate file under appender SQLFILE. But neither of them works. All the logs from org.jdbcdslog logged in console and in GENERIC_LOG_FILE, but not under the file given in appender SQLFILE. Please help.</p>
  
  <pre><code>  &lt;configuration scan="true"&gt;
      &lt;appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender"&gt;
          &lt;encoder&gt;
             &lt;pattern&gt;%d{yyyy-MM-dd HH:mm:ss}|%level|%logger|%msg%n&lt;/pattern&gt;
          &lt;/encoder&gt;
          &lt;filter class="ch.qos.logback.core.filter.EvaluatorFilter"&gt;
            &lt;evaluator&gt;
                &lt;expression&gt;return logger.startsWith("org.jdbcdslog")&lt;/expression&gt;
             &lt;/evaluator&gt;
            &lt;OnMatch&gt;DENY&lt;/OnMatch&gt;
            &lt;OnMismatch&gt;NEUTRAL&lt;/OnMismatch&gt;
          &lt;/filter&gt;
      &lt;/appender&gt;
      &lt;appender name="GENERAL_LOG_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"&gt;
            &lt;append&gt;true&lt;/append&gt;
             &lt;encoder&gt;
                  &lt;pattern&gt;%d{yyyy-MM-dd HH:mm:ss}|%level|%logger|%msg%n&lt;/pattern&gt;
             &lt;/encoder&gt;
              &lt;filter class="ch.qos.logback.core.filter.EvaluatorFilter"&gt;
                  &lt;evaluator&gt;
                      &lt;expression&gt;return logger.startsWith("org.jdbcdslog")&lt;/expression&gt;
                  &lt;/evaluator&gt;
                  &lt;OnMatch&gt;DENY&lt;/OnMatch&gt;
                  &lt;OnMismatch&gt;NEUTRAL&lt;/OnMismatch&gt;
              &lt;/filter&gt;
              &lt;rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"&gt;
                  &lt;fileNamePattern&gt;${user.home}/server.abacus.%d{yyyy-MM-dd}.log&lt;/fileNamePattern&gt;
                  &lt;maxHistory&gt;14&lt;/maxHistory&gt;
              &lt;/rollingPolicy&gt;
     &lt;/appender&gt;
     &lt;appender name="SQLFILE" class="ch.qos.logback.core.rolling.RollingFileAppender"&gt;
          &lt;append&gt;true&lt;/append&gt;
          &lt;!--&lt;filter class="ch.qos.logback.core.filter.EvaluatorFilter"&gt;
              &lt;evaluator&gt;
                  &lt;expression&gt;message.contains("TestFinished()")&lt;/expression&gt;
              &lt;/evaluator&gt;
              &lt;OnMatch&gt;DENY&lt;/OnMatch&gt;
              &lt;OnMismatch&gt;NEUTRAL&lt;/OnMismatch&gt;
          &lt;/filter&gt;--&gt;
          &lt;filter class="ch.qos.logback.core.filter.EvaluatorFilter"&gt;
              &lt;evaluator&gt; 
                  &lt;expression&gt;return logger.startsWith("org.jdbcdslog");&lt;/expression&gt;
              &lt;/evaluator&gt;
              &lt;OnMatch&gt;ACCEPT&lt;/OnMatch&gt;
              &lt;OnMismatch&gt;DENY&lt;/OnMismatch&gt;
          &lt;/filter&gt;
          &lt;encoder&gt;
              &lt;pattern&gt;%d{yyyy-MM-dd HH:mm:ss}|%level|%logger|%msg%n&lt;/pattern&gt;
          &lt;/encoder&gt;
          &lt;rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"&gt;
              &lt;!-- daily rollover --&gt;
              &lt;fileNamePattern&gt;${user.home}/all_query.abacus.%d{yyyy-MM-dd}.log&lt;/fileNamePattern&gt;
              &lt;maxHistory&gt;14&lt;/maxHistory&gt;
          &lt;/rollingPolicy&gt;
      &lt;/appender&gt;
      &lt;logger name="org.jdbcdslog.SlowQueryLogger" level="INFO"/&gt;
      &lt;logger name="org.jdbcdslog.StatementLogger" level="INFO"/&gt;
      &lt;root level="INFO"&gt;
        &lt;appender-ref ref="CONSOLE" /&gt;
        &lt;appender-ref ref="GENERAL_LOG_FILE" /&gt;
        &lt;appender-ref ref="ERROR_LOG_FILE" /&gt;
        &lt;appender-ref ref="PERF_LOG_FILE" /&gt;
        &lt;appender-ref ref="SQLFILE" /&gt;
        &lt;appender-ref ref="SLOWQUERY_SQLFILE" /&gt;
     &lt;/root&gt;
  </code></pre>
  
  <p></p>
  
  <p>Update 1:</p>
  
  <p>Here is the modified XML</p>
  
  <pre><code>&lt;configuration scan="true"&gt;
      &lt;appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender"&gt;
          &lt;encoder&gt;
              &lt;pattern&gt;%d{yyyy-MM-dd HH:mm:ss}|%level|%logger|%msg%n&lt;/pattern&gt;
          &lt;/encoder&gt;
      &lt;/appender&gt;
      &lt;appender name="GENERAL_LOG_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"&gt;
          &lt;append&gt;true&lt;/append&gt;
          &lt;filter class="ch.qos.logback.core.filter.EvaluatorFilter"&gt;
              &lt;evaluator&gt;
                  &lt;expression&gt;message.contains("TestFinished()")&lt;/expression&gt;
              &lt;/evaluator&gt;
              &lt;OnMatch&gt;DENY&lt;/OnMatch&gt;
              &lt;OnMismatch&gt;NEUTRAL&lt;/OnMismatch&gt;
          &lt;/filter&gt;
          &lt;filter class="ch.qos.logback.core.filter.EvaluatorFilter"&gt;
              &lt;evaluator&gt;
                  &lt;expression&gt;return logger.startsWith("Perf");&lt;/expression&gt;
              &lt;/evaluator&gt;
              &lt;OnMatch&gt;DENY&lt;/OnMatch&gt;
              &lt;OnMismatch&gt;ACCEPT&lt;/OnMismatch&gt;
          &lt;/filter&gt;
          &lt;encoder&gt;
              &lt;pattern&gt;%d{yyyy-MM-dd HH:mm:ss}|%level|%logger|%msg%n&lt;/pattern&gt;
          &lt;/encoder&gt;
          &lt;rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"&gt;
              &lt;fileNamePattern&gt;${user.home}/server.abacus.%d{yyyy-MM-dd}.log&lt;/fileNamePattern&gt;
              &lt;maxHistory&gt;14&lt;/maxHistory&gt;
          &lt;/rollingPolicy&gt;
      &lt;/appender&gt;
      &lt;appender name="ERROR_LOG_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"&gt;
          &lt;filter class="ch.qos.logback.core.filter.EvaluatorFilter"&gt;
              &lt;evaluator&gt;
                  &lt;expression&gt;message.contains("TestFinished()")&lt;/expression&gt;
              &lt;/evaluator&gt;
              &lt;OnMatch&gt;DENY&lt;/OnMatch&gt;
              &lt;OnMismatch&gt;NEUTRAL&lt;/OnMismatch&gt;
          &lt;/filter&gt;
          &lt;filter class="ch.qos.logback.classic.filter.LevelFilter"&gt;
              &lt;level&gt;ERROR&lt;/level&gt;
              &lt;onMatch&gt;ACCEPT&lt;/onMatch&gt;
              &lt;onMismatch&gt;DENY&lt;/onMismatch&gt;
          &lt;/filter&gt;
          &lt;append&gt;true&lt;/append&gt;
          &lt;encoder&gt;
              &lt;pattern&gt;%d{yyyy-MM-dd HH:mm:ss}|%level|%logger|%msg%n&lt;/pattern&gt;
          &lt;/encoder&gt;
          &lt;rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"&gt;
              &lt;fileNamePattern&gt;${user.home}/server.abacus.error.%d{yyyy-MM-dd}.log&lt;/fileNamePattern&gt;
              &lt;maxHistory&gt;14&lt;/maxHistory&gt;
          &lt;/rollingPolicy&gt;
      &lt;/appender&gt;
      &lt;appender name="PERF_LOG_FILE"
          class="ch.qos.logback.core.rolling.RollingFileAppender"&gt;
          &lt;append&gt;true&lt;/append&gt;
          &lt;filter class="ch.qos.logback.core.filter.EvaluatorFilter"&gt;
              &lt;evaluator&gt;
                  &lt;expression&gt;message.contains("TestFinished()")&lt;/expression&gt;
              &lt;/evaluator&gt;
              &lt;OnMatch&gt;DENY&lt;/OnMatch&gt;
              &lt;OnMismatch&gt;NEUTRAL&lt;/OnMismatch&gt;
          &lt;/filter&gt;
          &lt;filter class="ch.qos.logback.core.filter.EvaluatorFilter"&gt;
              &lt;evaluator&gt; 
                  &lt;expression&gt;return logger.startsWith("Perf");&lt;/expression&gt;
              &lt;/evaluator&gt;
              &lt;OnMatch&gt;ACCEPT&lt;/OnMatch&gt;
              &lt;OnMismatch&gt;DENY&lt;/OnMismatch&gt;
          &lt;/filter&gt;
          &lt;encoder&gt;
              &lt;pattern&gt;%d{yyyy-MM-dd HH:mm:ss}|%level|%logger|%msg%n&lt;/pattern&gt;
          &lt;/encoder&gt;
          &lt;rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"&gt;
              &lt;!-- daily rollover --&gt;
              &lt;fileNamePattern&gt;${user.home}/perf.abacus.%d{yyyy-MM-dd}.log&lt;/fileNamePattern&gt;
              &lt;maxHistory&gt;14&lt;/maxHistory&gt;
          &lt;/rollingPolicy&gt;
      &lt;/appender&gt;
      &lt;appender name="SQLFILE"
          class="ch.qos.logback.core.rolling.RollingFileAppender"&gt;
          &lt;append&gt;true&lt;/append&gt;
          &lt;encoder&gt;
              &lt;pattern&gt;%d{yyyy-MM-dd HH:mm:ss}|%level|%logger|%msg%n&lt;/pattern&gt;
          &lt;/encoder&gt;
          &lt;rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"&gt;
              &lt;!-- daily rollover --&gt;
              &lt;fileNamePattern&gt;${user.home}/all_query.%d{yyyy-MM-dd}.log&lt;/fileNamePattern&gt;
              &lt;maxHistory&gt;14&lt;/maxHistory&gt;
          &lt;/rollingPolicy&gt;
      &lt;/appender&gt;
      &lt;appender name="SLOWQUERY_SQLFILE"
          class="ch.qos.logback.core.rolling.RollingFileAppender"&gt;
          &lt;append&gt;true&lt;/append&gt;
          &lt;encoder&gt;
              &lt;pattern&gt;%d{yyyy-MM-dd HH:mm:ss}|%level|%logger|%msg%n&lt;/pattern&gt;
          &lt;/encoder&gt;
          &lt;rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"&gt;
              &lt;fileNamePattern&gt;${user.home}/slow_query.%d{yyyy-MM-dd}.log&lt;/fileNamePattern&gt;
              &lt;maxHistory&gt;14&lt;/maxHistory&gt;
          &lt;/rollingPolicy&gt;
      &lt;/appender&gt;
      &lt;logger name="ab.xyz" level="INFO" /&gt;
      &lt;logger name="bd.xyz" level="INFO" /&gt;
      &lt;logger name="net.sf.hibernate" level="WARN" /&gt;
      &lt;logger name="org.springframework" level="WARN" /&gt;
      &lt;logger name="jdbc.sqlonly" level="ERROR" /&gt;
      &lt;logger name="Perf" level="INFO" /&gt;
      &lt;logger name="org.jdbcdslog.SlowQueryLogger" level="INFO" additivity="false"&gt;
          &lt;appender-ref ref="SLOWQUERY_SQLFILE" /&gt;
      &lt;/logger&gt;
      &lt;logger name="org.jdbcdslog.StatementLogger" level="INFO" additivity="false"&gt;
          &lt;appender-ref ref="SQLFILE" /&gt;
      &lt;/logger&gt;
      &lt;logger name="org.jdbcdslog.ConnectionLogger" level="ERROR"/&gt;
      &lt;logger name="org.jdbcdslog.ResultSetLogger" level="ERROR"/&gt;
  
      &lt;root level="INFO"&gt;
          &lt;appender-ref ref="CONSOLE" /&gt;
          &lt;appender-ref ref="GENERAL_LOG_FILE" /&gt;
          &lt;appender-ref ref="ERROR_LOG_FILE" /&gt;
          &lt;appender-ref ref="PERF_LOG_FILE" /&gt;
      &lt;/root&gt;
  
  
  &lt;/configuration&gt;
  </code></pre>
  
  <p>Update 2:</p>
  
  <pre><code>&lt;configuration scan="true"&gt;
      &lt;appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender"&gt;
          &lt;encoder&gt;
              &lt;pattern&gt;%d{yyyy-MM-dd HH:mm:ss}|%level|%logger|%msg%n&lt;/pattern&gt;
          &lt;/encoder&gt;
      &lt;/appender&gt;
      &lt;appender name="GENERAL_LOG_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"&gt;
          &lt;append&gt;true&lt;/append&gt;
          &lt;filter class="ch.qos.logback.core.filter.EvaluatorFilter"&gt;
              &lt;evaluator&gt;
                  &lt;expression&gt;message.contains("TestFinished()")&lt;/expression&gt;
              &lt;/evaluator&gt;
              &lt;OnMatch&gt;DENY&lt;/OnMatch&gt;
              &lt;OnMismatch&gt;NEUTRAL&lt;/OnMismatch&gt;
          &lt;/filter&gt;
          &lt;filter class="ch.qos.logback.core.filter.EvaluatorFilter"&gt;
              &lt;evaluator&gt;
                  &lt;expression&gt;return logger.startsWith("Perf");&lt;/expression&gt;
              &lt;/evaluator&gt;
              &lt;OnMatch&gt;DENY&lt;/OnMatch&gt;
              &lt;OnMismatch&gt;ACCEPT&lt;/OnMismatch&gt;
          &lt;/filter&gt;
          &lt;encoder&gt;
              &lt;pattern&gt;%d{yyyy-MM-dd HH:mm:ss}|%level|%logger|%msg%n&lt;/pattern&gt;
          &lt;/encoder&gt;
          &lt;rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"&gt;
              &lt;fileNamePattern&gt;${user.home}/server.abacus.%d{yyyy-MM-dd}.log&lt;/fileNamePattern&gt;
              &lt;maxHistory&gt;14&lt;/maxHistory&gt;
          &lt;/rollingPolicy&gt;
      &lt;/appender&gt;
      &lt;appender name="ERROR_LOG_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"&gt;
          &lt;filter class="ch.qos.logback.core.filter.EvaluatorFilter"&gt;
              &lt;evaluator&gt;
                  &lt;expression&gt;message.contains("TestFinished()")&lt;/expression&gt;
              &lt;/evaluator&gt;
              &lt;OnMatch&gt;DENY&lt;/OnMatch&gt;
              &lt;OnMismatch&gt;NEUTRAL&lt;/OnMismatch&gt;
          &lt;/filter&gt;
          &lt;filter class="ch.qos.logback.classic.filter.LevelFilter"&gt;
              &lt;level&gt;ERROR&lt;/level&gt;
              &lt;onMatch&gt;ACCEPT&lt;/onMatch&gt;
              &lt;onMismatch&gt;DENY&lt;/onMismatch&gt;
          &lt;/filter&gt;
          &lt;append&gt;true&lt;/append&gt;
          &lt;encoder&gt;
              &lt;pattern&gt;%d{yyyy-MM-dd HH:mm:ss}|%level|%logger|%msg%n&lt;/pattern&gt;
          &lt;/encoder&gt;
          &lt;rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"&gt;
              &lt;fileNamePattern&gt;${user.home}/server.abacus.error.%d{yyyy-MM-dd}.log&lt;/fileNamePattern&gt;
              &lt;maxHistory&gt;14&lt;/maxHistory&gt;
          &lt;/rollingPolicy&gt;
      &lt;/appender&gt;
      &lt;appender name="PERF_LOG_FILE"
          class="ch.qos.logback.core.rolling.RollingFileAppender"&gt;
          &lt;append&gt;true&lt;/append&gt;
          &lt;filter class="ch.qos.logback.core.filter.EvaluatorFilter"&gt;
              &lt;evaluator&gt;
                  &lt;expression&gt;message.contains("TestFinished()")&lt;/expression&gt;
              &lt;/evaluator&gt;
              &lt;OnMatch&gt;DENY&lt;/OnMatch&gt;
              &lt;OnMismatch&gt;NEUTRAL&lt;/OnMismatch&gt;
          &lt;/filter&gt;
          &lt;filter class="ch.qos.logback.core.filter.EvaluatorFilter"&gt;
              &lt;evaluator&gt; 
                  &lt;expression&gt;return logger.startsWith("Perf");&lt;/expression&gt;
              &lt;/evaluator&gt;
              &lt;OnMatch&gt;ACCEPT&lt;/OnMatch&gt;
              &lt;OnMismatch&gt;DENY&lt;/OnMismatch&gt;
          &lt;/filter&gt;
          &lt;encoder&gt;
              &lt;pattern&gt;%d{yyyy-MM-dd HH:mm:ss}|%level|%logger|%msg%n&lt;/pattern&gt;
          &lt;/encoder&gt;
          &lt;rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"&gt;
              &lt;!-- daily rollover --&gt;
              &lt;fileNamePattern&gt;${user.home}/perf.abacus.%d{yyyy-MM-dd}.log&lt;/fileNamePattern&gt;
              &lt;maxHistory&gt;14&lt;/maxHistory&gt;
          &lt;/rollingPolicy&gt;
      &lt;/appender&gt;
      &lt;appender name="SQLFILE"
          class="ch.qos.logback.core.rolling.RollingFileAppender"&gt;
          &lt;append&gt;true&lt;/append&gt;
          &lt;encoder&gt;
              &lt;pattern&gt;%d{yyyy-MM-dd HH:mm:ss}|%level|%logger|%msg%n&lt;/pattern&gt;
          &lt;/encoder&gt;
          &lt;rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"&gt;
              &lt;!-- daily rollover --&gt;
              &lt;fileNamePattern&gt;${user.home}/all_query.%d{yyyy-MM-dd}.log&lt;/fileNamePattern&gt;
              &lt;maxHistory&gt;14&lt;/maxHistory&gt;
          &lt;/rollingPolicy&gt;
      &lt;/appender&gt;
      &lt;appender name="SLOWQUERY_SQLFILE"
          class="ch.qos.logback.core.rolling.RollingFileAppender"&gt;
          &lt;append&gt;true&lt;/append&gt;
          &lt;encoder&gt;
              &lt;pattern&gt;%d{yyyy-MM-dd HH:mm:ss}|%level|%logger|%msg%n&lt;/pattern&gt;
          &lt;/encoder&gt;
          &lt;rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"&gt;
              &lt;fileNamePattern&gt;${user.home}/slow_query.%d{yyyy-MM-dd}.log&lt;/fileNamePattern&gt;
              &lt;maxHistory&gt;14&lt;/maxHistory&gt;
          &lt;/rollingPolicy&gt;
      &lt;/appender&gt;
      &lt;logger name="ab.xyz" level="INFO" /&gt;
      &lt;logger name="cd.xyz" level="INFO" /&gt;
      &lt;logger name="net.sf.hibernate" level="WARN" /&gt;
      &lt;logger name="org.springframework" level="WARN" /&gt;
      &lt;logger name="jdbc.sqlonly" level="ERROR" /&gt;
      &lt;logger name="Perf" level="INFO" /&gt;
      &lt;logger name="org.jdbcdslog.SlowQueryLogger" level="INFO" additivity="false"&gt;
          &lt;appender-ref ref="SLOWQUERY_SQLFILE" /&gt;
      &lt;/logger&gt;
      &lt;logger name="org.jdbcdslog.StatementLogger" level="INFO" additivity="false"&gt;
          &lt;appender-ref ref="SQLFILE" /&gt;
      &lt;/logger&gt;
      &lt;logger name="org.jdbcdslog.ConnectionLogger" level="ERROR"/&gt;
      &lt;logger name="org.jdbcdslog.ResultSetLogger" level="ERROR"/&gt;
  
      &lt;root level="INFO"&gt;
          &lt;appender-ref ref="CONSOLE" /&gt;
          &lt;appender-ref ref="GENERAL_LOG_FILE" /&gt;
          &lt;appender-ref ref="ERROR_LOG_FILE" /&gt;
          &lt;appender-ref ref="PERF_LOG_FILE" /&gt;
          &lt;appender-ref ref="SQLFILE" /&gt;
          &lt;appender-ref ref="SLOWQUERY_SQLFILE" /&gt;
      &lt;/root&gt;
  &lt;/configuration&gt;
  </code></pre>