Java by API/java.util.logging/Filter
implements Filter
import java.util.logging.Filter;
import java.util.logging.Level;
import java.util.logging.LogRecord;
import java.util.logging.Logger;
public class Main {
private static Logger logger = Logger.getLogger("SimpleFilter");
static class A {
};
static class B {
};
static void sendLogMessages() {
logger.log(Level.WARNING, "message 1!", new A());
logger.log(Level.WARNING, "message 2!", new B());
}
public static void main(String[] args) {
sendLogMessages();
logger.setFilter(new Filter() {
public boolean isLoggable(LogRecord record) {
Object[] params = record.getParameters();
if (params == null)
return true;
if (record.getParameters()[0] instanceof A)
return true;
return false;
}
});
logger.info("After setting filter..");
sendLogMessages();
}
}