[logback-user] Filtering "unknown" mdc discriminator events

ceki ceki at qos.ch
Sat Sep 22 18:33:23 CEST 2012


The <OnMismatch> and <OnMatch> elements should be embedded in the 
<filter> element, and not the <evaluator> element.

On 22.09.2012 18:16, Fred Toth wrote:
> Hi,
>
> This has been written about before in this list, and I thought it would
> be easy, but I'm getting nowhere. Can anyone suggest what I'm doing
> wrong? I can confirm that my filter code is running (I see the print
> statements) but no matter what I return, I still end up with a log like
> "unknown/batchqc-<timestamp>" containing plenty of log data.
>
> I would like to eliminate these logs completely, and write logs using
> this sifter only when articlePath is set.
>
> The status listener is reporting:
>
> 12:03:35,652 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter at 25:37
> - no applicable action for [OnMismatch], current pattern is
> [[configuration][appender][filter][evaluator][OnMismatch]]
> 12:03:35,652 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter at 26:34
> - no applicable action for [OnMatch], current pattern is
> [[configuration][appender][filter][evaluator][OnMatch]]
>
> What am I missing?
>
> Config:
>
> <configuration>
>
>      <statusListener
> class="ch.qos.logback.core.status.OnConsoleStatusListener"/>
>
>      <timestamp key="bySecond" datePattern="yyyy-MM-dd-HH-mm-ss" />
>      <timestamp key="byDate" datePattern="yyyy-MM-dd" />
>
>      <appender name="ARTICLESIFT"
> class="ch.qos.logback.classic.sift.SiftingAppender">
>          <discriminator>
>              <key>articlePath</key>
>              <defaultValue>unknown</defaultValue>
>          </discriminator>
>          <sift>
>              <appender name="ARTICLESIFT-APPENDER"
> class="ch.qos.logback.core.FileAppender">
>                  <filter
> class="ch.qos.logback.core.filter.EvaluatorFilter">
>                      <evaluator
> class="ch.qos.logback.classic.boolex.JaninoEventEvaluator">
>                          <expression>
> System.out.println("MDC: " + mdc + " " + mdc.get("articlePath"));
> if (mdc == null
>      || mdc.get("articlePath") == null
>      || ((String)mdc.get("articlePath")).contains("unknown"))
>          return false;
> return true;
>                          </expression>
>                          <OnMismatch>NEUTRAL</OnMismatch>
>                          <OnMatch>DENY</OnMatch>
>                      </evaluator>
>                  </filter>
> <file>${articlePath}/batchqc-${bySecond}.log</file>
>                  <append>false</append>
>                  <encoder
> class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
>                      <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level
> %logger{0} - %msg%n
>                      </pattern>
>                  </encoder>
>              </appender>
>          </sift>
>      </appender>
>
>      <appender name="TSFILE" class="ch.qos.logback.core.FileAppender">
>          <file>logs/batchqc-${byDate}.log</file>
>          <append>true</append>
>          <encoder>
>              <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level %logger{0} -
> %msg%n</pattern>
>          </encoder>
>      </appender>
>
>      <root level="info">
>          <appender-ref ref="TSFILE" />
>          <appender-ref ref="ARTICLESIFT" />
>      </root>
> </configuration>
>
> Thanks,
>
> Fred
>


-- 
Ceki
http://tinyurl.com/proLogback


More information about the Logback-user mailing list