Logger removeHandler() method in Java with Examples Last Updated : 24 Jun, 2021 Comments Improve Suggest changes Like Article Like Report removeHandler() method of a Logger class is used to remove a log Handler from Logger. A Handler is a component of JVM that takes care of actual logging to the defined output writers like a file, console out etc. It returns silently if the given Handler is not found or is null.Syntax: public void removeHandler(Handler handler) throws SecurityException Parameters: This method accepts one parameter handler which represents a logging Handler.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 removeHandler() method: Program 1: Java // Java program to demonstrate // Logger.removeHandler() method import java.util.logging.*; import java.io.IOException; public class GFG { private static Logger logger = Logger.getLogger( GFG.class.getName()); public static void main(String args[]) throws SecurityException, IOException { FileHandler filehandler = new FileHandler("logs.txt"); // Add file handler as // handler of logs logger.addHandler(filehandler); // Log message logger.info("This is Info Message "); // Remove file handler. logger.removeHandler(filehandler); logger.info("This message will " + "not print on filehandler"); } } Output: The output printed on logs.txt file is shown below- Program 2: Java // Java program to demonstrate // Logger.addHandler() method import java.util.logging.*; import java.io.IOException; public class GFG { private static Logger logger = Logger.getLogger( GFG.class.getName()); public static void main(String args[]) throws SecurityException, IOException { // Create a ConsoleHandler object ConsoleHandler handler = new ConsoleHandler(); // Add console handler as // handler of logs logger.addHandler(handler); // Log message logger.info("This is Info Message "); // Remove consolehandler logger.removeHandler(handler); // After removing logs print message logger.info("Handler removed"); } } Output: output printed on console output is shown below- Reference: https://docs.oracle.com/javase/10/docs/api/java/util/logging/Logger.html#removeHandler(java.util.logging.Handler) Comment More infoAdvertise with us Next Article Logger removeHandler() 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 severe() method in Java with Examples The severe() method of a Logger class used to Log a SEVERE message.This method is used to pass SEVERE types logs to all the registered output Handler objects. SEVERE Message: Severe occurs when something terrible has occurred and the application cannot continue further. Ex like database unavailable, 2 min read Logger setUseParentHandlers() method in Java with Examples setUseParentHandlers() method of a Logger class used to set the configuration which defines whether or not this logger should send its output to its parent Logger. if we want to send the output to its parent Logger then we have to set the parameter to this method equal to true. This means that any l 2 min read 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 interfac 2 min read List removeAll() method in Java with Examples This method is used to remove all the elements present in the collection from the specified list. Syntax: boolean removeAll(Collection c) Parameters: This method has only argument, collection of which elements are to be removed from the given list. Returns: This method returns True if elements are r 2 min read Logger throwing() method in Java with Examples throwing(String sourceClass, String sourceMethod, Throwable thrown) method is used to Log throwing an exception.In many scenario method is closed by throwing an exception then this is a very helpful method to log that a method is terminating by throwing an exception. The logging is done using the FI 2 min read Like