Logger setParent() method in Java with Examples
Last Updated :
26 Mar, 2019
setParent() method of a Logger class used to set the parent Logger of this current Logger.The parent Logger we want to set is passed as a parameter. LogManager use this method to update a Logger when the namespace changes.
Syntax:
public void setParent(Logger parent)
Parameters: This method accepts one parameter parent which represents the new parent logger.
Return value: This method returns nothing.
Exception: This method throws SecurityException if a security manager exists and if the caller does not have LoggingPermission(“control”).
Below programs illustrate the setParent() method:
Program 1:
import java.util.logging.*;
public class GFG {
public static void main(String[] args)
{
Logger logger1
= Logger.getLogger( "com.java.core" );
Logger logger2
= Logger
.getLogger( "com.java.core.api" );
logger2.setParent(logger1);
System.out.println( "logger2 parent name = "
+ logger2
.getParent()
.getName());
}
}
|
Output:
The output printed on console of Eclipse is shown below-
Program 2:
import java.util.logging.*;
public class GFG {
public static void main(String[] args)
{
Logger logger1
= Logger.getLogger(GFG. class .getName());
Logger logger2
= Logger
.getLogger(String. class .getName());
logger1.setParent(logger2);
System.out.println( "logger1 parent name = "
+ logger1
.getParent()
.getName());
}
}
|
Output:
The output printed on console output is shown below-
Reference: https://docs.oracle.com/javase/10/docs/api/java/util/logging/Logger.html#setParent(java.util.logging.Logger)
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...