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 log records will also be written to the parent’s Handlers, and potentially to its parent, recursively up the namespace.
Syntax:
public void setUseParentHandlers(boolean useParentHandlers)
Parameters: This method accepts one parameter useParentHandlers which represents true if output is to be sent to the logger’s parent.
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 setUseParentHandlers() method:
Program 1:
// Java program to demonstrate // Logger.setUseParentHandlers() method import java.util.logging.Logger; public class GFG { private static Logger logger = Logger.getLogger( GFG.class .getPackage() .getName()); public static void main(String args[]) { // Set that this logger will // sent logs to its parent logger. logger.setUseParentHandlers(true); // Log the flag value logger.info("output sent to the" + " logger's parent - " + logger.getUseParentHandlers()); } } |
Output:
The output printed on console of Eclipse is shown below-

Program 2:
// Java program to demonstrate // Logger.setUseParentHandlers() method import java.util.logging.Logger; public class GFG { private static Logger logger = Logger.getLogger( GFG.class .getPackage() .getName()); public static void main(String args[]) { // Set that this logger will not // send logs to its parent logger. logger.setUseParentHandlers(false); // Print the flag value System.out.println("output sent to the" + " logger's parent - " + logger.getUseParentHandlers()); } } |
Output:
The output printed on console output is shown below-

Recommended Posts:
- Logger log() Method in Java with Examples
- Logger removeHandler() method in Java with Examples
- Logger setLevel() method in Java with Examples
- Logger setParent() method in Java with Examples
- Logger setResourceBundle() method in Java with Examples
- Logger getName() Method in Java with Examples
- Logger warning() method in Java with Examples
- Logger getHandler() Method in Java with Examples
- Logger getFilter() Method in Java with Examples
- Logger exiting() method in Java with Examples
- Logger entering() method in Java with Examples
- Logger finer() method in Java with Examples
- Logger severe() method in Java with Examples
- Logger config() method in Java with Examples
- Logger fine() method in Java with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


