Logger setFilter() method in Java with Examples Last Updated : 26 Mar, 2019 Comments Improve Suggest changes Like Article Like Report 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. Syntax: 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: Program 1: Java // Java program to demonstrate // Logger.setFilter() method import java.util.logging.*; import java.io.IOException; public class GFG { public static void main(String[] args) throws SecurityException, IOException { // Create a logger Logger logger = Logger.getLogger(GFG.class.getName()); // set a new filter logger.setFilter(new MyFilter()); // check filter is null or not by printing System.out.println("Filter = " + logger.getFilter()); } } class MyFilter implements Filter { public boolean isLoggable(LogRecord record) { return false; } } Output: The output printed on console of Eclipse is shown below- Program 2: Java // Java program to demonstrate // Logger.setFilter() method import java.util.logging.*; import java.io.IOException; public class GFG { public static void main(String[] args) throws SecurityException, IOException { // Create a logger Logger logger = Logger.getLogger( GFG.class.getName()); // Set a new filter logger.setFilter(new Filter() { @Override public boolean isLoggable(LogRecord record) { return true; } }); // Check filter is null // or not by printing System.out.println("Filter = " + logger.getFilter()); } } Output: The output printed on console output is shown below- References: https://docs.oracle.com/javase/10/docs/api/java/util/logging/Logger.html#setFilter(java.util.logging.Filter) Comment More infoAdvertise with us Next Article Logger setFilter() method in Java with Examples A AmanSingh2210 Follow Improve Article Tags : Java Java - util package Java-Functions Java-Logger Practice Tags : Java Similar Reads Logger setLevel() method in Java with Examples setLevel() method of a Logger class used to set the log level to describe which message levels will be logged by this logger. The level we want to set is passed as a parameter. Message levels lower than passed log level value will be discarded by the logger. The level value Level.OFF can be used to 2 min read Logger setParent() method in Java with Examples setParent() method of a Logger class used to set the parent Logger of this current Logger.The parent Logger we want to set is passed as a parameter. LogManager use this method to update a Logger when the namespace changes. Syntax: public void setParent(Logger parent) Parameters: This method accepts 2 min read LogManager reset() method in Java with Examples The reset() method of java.util.logging.LogManager is used to reset the logging configuration. This method throws SecurityException if the exception condition occurs, as given below Syntax: public void reset() throws SecurityException Parameters: This method does not accepts any parameter. Return Va 1 min read LogRecord setLevel() method in Java with Examples The setLevel() method of java.util.logging.LogRecord is used to set the level of logging message, for example Level.INFO for this LogRecord Object. Syntax: public void setLevel(Level level) Parameters: This method accepts level which is the logging message level. Return: This method returns nothing. 1 min read LogRecord setThrown() method in Java with Examples The setThrown() method of java.util.logging.LogRecord is used to a throwable associated with the log event.This is used to log Exceptions in the logRecord that can be used for logging messages. Syntax: public void setThrown(Throwable thrown) Parameters: This method accepts thrown as a parameter whic 2 min read Like