Java中的 LogManager getLoggerNames() 方法及示例
Java.util.logging.LogManager的getLoggerNames()方法用于获取已知记录器名称的列表。此方法以 Enumeration 对象的形式返回此列表。
句法:
public Enumeration getLoggerNames()
参数:此方法不接受任何参数。
返回值:此方法以枚举对象的形式返回已知记录器名称列表。
下面的程序说明了 getLoggerNames() 方法:
方案一:
// 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 listOfNames
= logManager.getLoggerNames();
System.out.println("List of Logger Names: ");
while (listOfNames.hasMoreElements())
System.out.println(listOfNames.nextElement());
}
}
输出:
List of Logger Names:
global
方案二:
// 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 listOfNames
= logManager.getLoggerNames();
System.out.println("\nList of Logger Names: ");
while (listOfNames.hasMoreElements())
System.out.println(listOfNames.nextElement());
}
}
输出:
List of Logger Names:
GFG
global
参考: https://docs.oracle.com/javase/9/docs/api/ Java/util/logging/LogManager.html#getLoggerNames–