in order to reduce the amount of logging present in our application, we decided to enable/disable logging of certain methods on a per-client basis.
public class LoggingFilter extends Filter<ILoggingEvent> {
@Autowired
private MethodNameValidator validator;
@Override
public FilterReply decide(ILoggingEvent event) {
Map<String, String> mdcProperties = event.getMDCPropertyMap();
if (mdcProperties.isEmpty()) {
return FilterReply.ACCEPT;
}
String accountId = mdcProperties.get(MDCUtil.ACCOUNT_ID);
String methodName = mdcProperties.get(MDCUtil.METHOD_NAME);
if (validator.isValidMethodName(accountId, methodName)) {
return FilterReply.ACCEPT;
}
return FilterReply.DENY;
}
}
The custom filter defined above has a validation component in which the method validation logic is implemented.
The validator is a Spring Bean (which is also exposed via JMX for external configuration).
I fail to inject the MethodNameValidator bean into the filter.
The filter is a bean also.
Is there a way to achieve this?
If I could set a logback filter dynamically then I could initialize my filter as a bean, get the desired logger by name and apply the filter.
Can't figure out how to do it via the provided Logback api.
This works for me.
2.
Thats how we nailed it. Turbo filters instead of event filters. Thx ;)