Friday, September 5, 2025
HomeLanguagesJavaLogManager getLoggerNames() method in Java with Examples

LogManager getLoggerNames() method in Java with Examples

The getLoggerNames() method of java.util.logging.LogManager is used to get a list of known logger names. This method returns this list in the form of an Enumeration object.

Syntax:

public Enumeration getLoggerNames()

Parameters: This method does not accepts any parameter.

Return Value: This method returns list of known logger names list in the form of an Enumeration object.

Below programs illustrate getLoggerNames() method:

Program 1:




// Java program to illustrate
// LogManager getLoggerNames() method
  
import java.util.logging.*;
import java.util.*;
  
public class GFG {
  
    public static void main(String[] args)
    {
  
        // Create LogManager object
        LogManager logManager
            = LogManager.getLogManager();
  
        Enumeration<String> listOfNames
            = logManager.getLoggerNames();
  
        System.out.println("List of Logger Names: ");
        while (listOfNames.hasMoreElements())
            System.out.println(listOfNames.nextElement());
    }
}


Output:

List of Logger Names: 
global

Program 2:




// Java program to illustrate
// LogManager getLoggerNames() method
  
import java.util.logging.*;
import java.util.*;
  
public class GFG {
  
    public static void main(String[] args)
    {
  
        // Create LogManager object
        LogManager logManager
            = LogManager.getLogManager();
  
        logManager.addLogger(Logger.getLogger("GFG"));
  
        Enumeration<String> listOfNames
            = logManager.getLoggerNames();
  
        System.out.println("\nList of Logger Names: ");
        while (listOfNames.hasMoreElements())
            System.out.println(listOfNames.nextElement());
    }
}


Output:

List of Logger Names: 
GFG
global

Reference: https://docs.oracle.com/javase/9/docs/api/java/util/logging/LogManager.html#getLoggerNames–

RELATED ARTICLES

Most Popular

Dominic
32264 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6634 POSTS0 COMMENTS
Nicole Veronica
11801 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11863 POSTS0 COMMENTS
Shaida Kate Naidoo
6750 POSTS0 COMMENTS
Ted Musemwa
7025 POSTS0 COMMENTS
Thapelo Manthata
6701 POSTS0 COMMENTS
Umr Jansen
6718 POSTS0 COMMENTS