本文整理汇总了Java中java.util.logging.LogManager.getLoggerNames方法的典型用法代码示例。如果您正苦于以下问题:Java LogManager.getLoggerNames方法的具体用法?Java LogManager.getLoggerNames怎么用?Java LogManager.getLoggerNames使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.logging.LogManager
的用法示例。
在下文中一共展示了LogManager.getLoggerNames方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: redirectInternalJavaLoggers
import java.util.logging.LogManager; //导入方法依赖的package包/类
public static void redirectInternalJavaLoggers() {
// Do we need to this on re-connect?
LogManager logManager = LogManager.getLogManager();
try {
Enumeration<String> loggerNames = logManager.getLoggerNames();
while (loggerNames.hasMoreElements()) {
String loggerName = loggerNames.nextElement();
if (loggerName.startsWith("java.") || loggerName.startsWith("javax.")) {
// System.out.println(loggerName);
Logger javaLogger = logManager.getLogger(loggerName);
/*
* From Java Docs: It is also important to note that the Logger associated with the String
* name may be garbage collected at any time if there is no strong reference to the
* Logger. The caller of this method must check the return value for null in order to
* properly handle the case where the Logger has been garbage collected.
*/
if (javaLogger != null) {
LogWrapper.getInstance().setParentFor(javaLogger);
}
}
}
} catch (SecurityException e) {
// e.printStackTrace();
LogWrapper.getInstance().warning(e.getMessage(), e);
}
}