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:
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:
import java.util.logging.Logger;
public class GFG {
private static Logger logger
= Logger.getLogger(
GFG. class
.getPackage()
.getName());
public static void main(String args[])
{
logger.setUseParentHandlers( true );
logger.info( "output sent to the"
+ " logger's parent - "
+ logger.getUseParentHandlers());
}
}
|
Output:
The output printed on console of Eclipse is shown below-
Program 2:
import java.util.logging.Logger;
public class GFG {
private static Logger logger
= Logger.getLogger(
GFG. class
.getPackage()
.getName());
public static void main(String args[])
{
logger.setUseParentHandlers( false );
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)
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...