Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Logger setUseParentHandlers() method in Java with Examples

  • Last Updated : 26 Mar, 2019

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:

Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.

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-

Reference: https://docs.oracle.com/javase/10/docs/api/java/util/logging/Logger.html#setUseParentHandlers(boolean)




My Personal Notes arrow_drop_up
Recommended Articles
Page :