I have project on old version of dropwizrd (0.9.3 where is no any log filter(https://www.dropwizard.io/en/release-0.9.x/manual/core.html#logging)) and I want to disable log for one url.
I try to use it:
package com.pack.service.services;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.filter.Filter;
import ch.qos.logback.core.spi.FilterReply;
public class LogFilter extends Filter<ILoggingEvent> {
final static String SPAM_URL = "spam";
@Override
public FilterReply decide(ILoggingEvent event) {
if (!event.getMessage().contains(SPAM_URL)) {
return FilterReply.ACCEPT;
} else {
return FilterReply.NEUTRAL;
}
}
}
And in folder resources in log4j2.xml file I added it:
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="ERROR" >
<Appenders>
<Filter class="com.pack.service.services.LogFilter"/>
<Console name="console" target="SYSTEM_OUT">
<PatternLayout pattern="[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n" />
</Console>
</Appenders>
<Loggers>
<Root level="error" additivity="false">
<AppenderRef ref="console" />
</Root>
</Loggers>
</Configuration>
But I got the error:
2021-04-01 16:26:33,473 main ERROR Appenders contains an invalid element or attribute "filter"
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…