Logger setFilter() method in Java with Examples
setFilter() method of a Logger class is used to set a filter to control output on this Logger. The filter is passed as a parameter. A Filter is useful to filter out log messages. It can be said that the filter decides the message gets to be logged or not. Filters are represented by the Java interface java.util.logging.Filter. After passing the initial “level” check, the Logger will call this Filter to check if a log record should really be published.
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.
public void setFilter(Filter newFilter) throws SecurityException
Parameters: This method accepts one parameter newFilter which represents a filter object.
Return value: This method returns nothing.
Exception: This method throws SecurityException if a security manager exists, this logger is not anonymous, and the caller does not have LoggingPermission(“control”).
Below programs illustrate the setFilter() method:
The output printed on console of Eclipse is shown below-
The output printed on console output is shown below-