Logger getName() Method in Java with Examples
getName() method of a Logger class used to get the name of logger. Many times you have to check the logger name so we can use this method to get the logger name.
Syntax:
public String getName()
Parameters: This method accepts nothing.
Return value: This method return logger name and it will be null for anonymous Loggers.
Below programs illustrate the getName() method:
Program 1:
// Java program to demonstrate // Logger.getName() method import java.util.logging.*; public class GFG { // Create a logger using getGLobal() static Logger logger1 = Logger.getGlobal(); // Create a logger using getLogger() static Logger logger2 = Logger.getLogger("com.gfg"); public static void main(String[] args) { System.out.println("logger1 name = " + logger1.getName()); System.out.println("logger2 name = " + logger2.getName()); } } |
logger1 name = global logger2 name = com.gfg
Program 2:
// Java program to demonstrate // Logger.getName() method import java.util.logging.*; public class GFG { // Create a logger using getLogger() static Logger logger = Logger.getLogger("com.gfg.logger."); public static void main(String[] args) { System.out.println("logger name = " + logger.getName()); } } |
logger name = com.gfg.logger.
Reference: https://docs.oracle.com/javase/10/docs/api/java/util/logging/Logger.html#getName()
Recommended Posts:
- Provider getName() method in Java with Examples
- Field getName() method in Java with Examples
- Level getName() method in Java with Examples
- File getName() method in Java with Examples
- Path getName(int) method in Java with Examples
- Logger log() Method in Java with Examples
- Logger addHandler() method in Java with Examples
- Logger setFilter() method in Java with Examples
- Logger getAnonymousLogger() Method in Java with Examples
- Logger getResourceBundleName() method in Java with Examples
- Logger config() method in Java with Examples
- Logger warning() method in Java with Examples
- Logger getUseParentHandlers() Method in Java with Examples
- Logger finer() method in Java with Examples
- Logger throwing() 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.



