Logger getParent() Method in Java with Examples
getParent() method of a Logger class is used to get the parent of this Logger.This method returns the nearest extant parent in the namespace.if there is a Logger called “com.javac.core.api”, and a Logger called “com.javac” has been created but no logger “com.javac.core” exists, then a call of getParent on the Logger “com.javac.core.api” will return the Logger “com.javac”. The result will be null if we apply getParent() method on root Logger in the namespace.
Syntax:
public Logger getParent()
Parameters: This method accepts nothing.
Return value: This method return nearest existing parent Logger.
Below programs illustrate the getName() method:
Program 1:
// Java program to demonstrate // Logger.getParent() method import java.util.logging.*; public class GFG { public static void main(String[] args) { // Create a logger using getLogger() Logger logger = Logger.getLogger("com.java.core"); // Assign other package to logger logger = Logger .getLogger("com.java.core.api"); // Print parent name System.out.println("logger name = " + logger .getParent() .getName()); } } |
logger name = com.java.core
Program 2:
// Java program to demonstrate // Logger.getParent() method import java.util.logging.*; public class GFG { public static void main(String[] args) { // Create a logger using getLogger() Logger logger = Logger.getLogger("com.java"); // Assign other package to logger logger = Logger.getLogger("com.java.core.api.base"); // Get Parent logger Logger parentLogger = logger.getParent(); // Print parent name System.out.println("Parent logger name = " + parentLogger.getName()); } } |
Parent logger name = com.java
References: https://docs.oracle.com/javase/10/docs/api/java/util/logging/Logger.html#getParent()
Recommended Posts:
- File getParent() method in Java with Examples
- Path getParent() method in Java with Examples
- Logger log() Method in Java with Examples
- Logger getAnonymousLogger() Method in Java with Examples
- Logger getLogger() Method in Java with Examples
- Logger fine() method in Java with Examples
- Logger getName() Method in Java with Examples
- Logger finest() method in Java with Examples
- Logger getResourceBundle() Method in Java with Examples
- Logger setUseParentHandlers() method in Java with Examples
- Logger getGlobal() Method in Java with Examples
- Logger setLevel() method in Java with Examples
- Logger getUseParentHandlers() Method in Java with Examples
- Logger isLoggable() method in Java with Examples
- Logger getResourceBundleName() 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.



