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-