[logback-user] Filtering "unknown" mdc discriminator events
Fred Toth
ftoth at synernet.com
Sat Sep 22 18:51:59 CEST 2012
Wow, that was quick! And simple! Yes, of course that fixed it.
However, one good answer deserves another question:
I now have empty logs being created, which is a step in the right
direction. But can I eliminate the "unknown" logs completely? Right now
every time my app fires up it creates an "unknown" directory and the
empty timestamped log. Since this is a long running batch application, I
will quickly end up with a bunch of these and it would be great if I
could prevent them completely.
Possible?
Thanks very much for your quick response.
Fred
On 9/22/2012 12:33 PM, ceki wrote:
>
> 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
>>
>
>
More information about the Logback-user
mailing list