Logger getFilter() Method in Java with Examples
Last Updated :
20 Mar, 2019
The getFilter() method of the Logger class is used to get the current filter for this Logger instance. A Filter is useful to filter out log messages. we can say that filter decide the message gets logged or not. Filters are represented by the Java interface java.util.logging.Filter
Syntax:
public Filter getFilter()
Parameters: This method accepts do not accepts any parameter.
Return value: This method returns the current filter for this Logger.
Below programs illustrate the getFilter() method:
Program 1:
import java.util.logging.*;
import java.io.IOException;
public class GFG {
public static void main(String[] args)
throws SecurityException, IOException
{
Logger logger = Logger.getLogger( "com.core" );
logger.setFilter( new Filter() {
@Override
public boolean isLoggable(LogRecord record)
{
return true ;
}
});
Filter filter = logger.getFilter();
System.out.println( "Filter = " + filter);
}
}
|
Output:
The output printed on eclipse IDE is shown below-
Program 2:
import java.util.logging.*;
import java.io.IOException;
public class GFG {
public static void main(String[] args)
throws SecurityException, IOException
{
Logger logger
= Logger.getLogger( "com.javacode.core" );
logger.setFilter( new MyFilter());
Filter filter = logger.getFilter();
System.out.println( "Filter = " + filter);
}
}
class MyFilter implements Filter {
public boolean isLoggable(LogRecord record)
{
return false ;
}
}
|
Output:
The output printed on eclipse IDE is shown below-
Reference: https://docs.oracle.com/javase/10/docs/api/java/util/logging/Logger.html#getFilter()
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...