List of usage examples for java.util.logging LogManager getLoggerNames
public Enumeration<String> getLoggerNames()
From source file:mitm.common.util.LogUtils.java
/** * Disables all Log4J and JSE logging.// w w w .ja v a 2s. co m */ public static void disableLogging() { /* * Disable Log4J logging. */ BasicConfigurator.configure(new NullAppender()); /* * Disable JSE logging */ java.util.logging.LogManager logManager = java.util.logging.LogManager.getLogManager(); Enumeration<String> loggerEnum = logManager.getLoggerNames(); while (loggerEnum.hasMoreElements()) { String loggerName = loggerEnum.nextElement(); java.util.logging.Logger.getLogger(loggerName).setLevel(java.util.logging.Level.OFF); } }
From source file:com.l2jfree.L2Config.java
/** Flushes all pending log entries. */ // FIXME MMOLogger.flush() public static void flush() { // those are redirected to loggers, so flush them first System.out.flush();/*w w w. j a v a2 s . c o m*/ System.err.flush(); // then flush the loggers themselves final LogManager logManager = LogManager.getLogManager(); for (String loggerName : Collections.list(logManager.getLoggerNames())) { if (loggerName == null) continue; final Logger logger = logManager.getLogger(loggerName); if (logger == null) continue; for (Handler handler : logger.getHandlers()) if (handler != null) handler.flush(); } // and finally the real console streams L2Config.out.flush(); L2Config.err.flush(); }
From source file:com.ellychou.todo.rest.service.SpringContextJerseyTest.java
/** * Retrieves a list of root loggers./*from w w w . j a v a2s . c o m*/ * * @return list of root loggers. */ private Set<Logger> getRootLoggers() { final LogManager logManager = LogManager.getLogManager(); final Enumeration<String> loggerNames = logManager.getLoggerNames(); final Set<Logger> rootLoggers = Sets.newHashSet(); while (loggerNames.hasMoreElements()) { Logger logger = logManager.getLogger(loggerNames.nextElement()); if (logger != null) { while (logger.getParent() != null) { logger = logger.getParent(); } rootLoggers.add(logger); } } return rootLoggers; }
From source file:fr.jmmc.jmcs.logging.LogbackGui.java
/** * Resolve all existing J.U.L Logger as logback Loggers to see them in the configuration *///from w ww .ja va 2s. c om private void visitJulLoggers() { _logger.debug("visitJulLoggers: start"); java.util.logging.LogManager julManager = java.util.logging.LogManager.getLogManager(); for (Enumeration<String> e = julManager.getLoggerNames(); e.hasMoreElements();) { final String loggerName = e.nextElement(); if (!StringUtils.isEmpty(loggerName)) { _logger.debug("JUL logger: {}", loggerName); // Resolve Logback logger: LoggerFactory.getLogger(loggerName); } } _logger.debug("visitJulLoggers: end"); }
From source file:MailHandlerDemo.java
/** * Used debug problems with the logging.properties. The system property * java.security.debug=access,stack can be used to trace access to the * LogManager reset./*w w w . j a v a 2 s .com*/ * * @param prefix a string to prefix the output. * @param err any PrintStream or null for System.out. */ @SuppressWarnings("UseOfSystemOutOrSystemErr") private static void checkConfig(String prefix, PrintStream err) { if (prefix == null || prefix.trim().length() == 0) { prefix = "DEBUG"; } if (err == null) { err = System.out; } try { err.println(prefix + ": java.version=" + System.getProperty("java.version")); err.println(prefix + ": LOGGER=" + LOGGER.getLevel()); err.println(prefix + ": JVM id " + ManagementFactory.getRuntimeMXBean().getName()); err.println(prefix + ": java.security.debug=" + System.getProperty("java.security.debug")); SecurityManager sm = System.getSecurityManager(); if (sm != null) { err.println(prefix + ": SecurityManager.class=" + sm.getClass().getName()); err.println(prefix + ": SecurityManager classLoader=" + toString(sm.getClass().getClassLoader())); err.println(prefix + ": SecurityManager.toString=" + sm); } else { err.println(prefix + ": SecurityManager.class=null"); err.println(prefix + ": SecurityManager.toString=null"); err.println(prefix + ": SecurityManager classLoader=null"); } String policy = System.getProperty("java.security.policy"); if (policy != null) { File f = new File(policy); err.println(prefix + ": AbsolutePath=" + f.getAbsolutePath()); err.println(prefix + ": CanonicalPath=" + f.getCanonicalPath()); err.println(prefix + ": length=" + f.length()); err.println(prefix + ": canRead=" + f.canRead()); err.println(prefix + ": lastModified=" + new java.util.Date(f.lastModified())); } LogManager manager = LogManager.getLogManager(); String key = "java.util.logging.config.file"; String cfg = System.getProperty(key); if (cfg != null) { err.println(prefix + ": " + cfg); File f = new File(cfg); err.println(prefix + ": AbsolutePath=" + f.getAbsolutePath()); err.println(prefix + ": CanonicalPath=" + f.getCanonicalPath()); err.println(prefix + ": length=" + f.length()); err.println(prefix + ": canRead=" + f.canRead()); err.println(prefix + ": lastModified=" + new java.util.Date(f.lastModified())); } else { err.println(prefix + ": " + key + " is not set as a system property."); } err.println(prefix + ": LogManager.class=" + manager.getClass().getName()); err.println(prefix + ": LogManager classLoader=" + toString(manager.getClass().getClassLoader())); err.println(prefix + ": LogManager.toString=" + manager); err.println(prefix + ": MailHandler classLoader=" + toString(MailHandler.class.getClassLoader())); err.println( prefix + ": Context ClassLoader=" + toString(Thread.currentThread().getContextClassLoader())); err.println(prefix + ": Session ClassLoader=" + toString(Session.class.getClassLoader())); err.println(prefix + ": DataHandler ClassLoader=" + toString(DataHandler.class.getClassLoader())); final String p = MailHandler.class.getName(); key = p.concat(".mail.to"); String to = manager.getProperty(key); err.println(prefix + ": TO=" + to); if (to != null) { err.println(prefix + ": TO=" + Arrays.toString(InternetAddress.parse(to, true))); } key = p.concat(".mail.from"); String from = manager.getProperty(key); if (from == null || from.length() == 0) { Session session = Session.getInstance(new Properties()); InternetAddress local = InternetAddress.getLocalAddress(session); err.println(prefix + ": FROM=" + local); } else { err.println(prefix + ": FROM=" + Arrays.asList(InternetAddress.parse(from, false))); err.println(prefix + ": FROM=" + Arrays.asList(InternetAddress.parse(from, true))); } synchronized (manager) { final Enumeration<String> e = manager.getLoggerNames(); while (e.hasMoreElements()) { final Logger l = manager.getLogger(e.nextElement()); if (l != null) { final Handler[] handlers = l.getHandlers(); if (handlers.length > 0) { err.println(prefix + ": " + l.getClass().getName() + ", " + l.getName()); for (Handler h : handlers) { err.println(prefix + ":\t" + toString(prefix, err, h)); } } } } } } catch (Throwable error) { err.print(prefix + ": "); error.printStackTrace(err); } err.flush(); }
From source file:org.hippoecm.repository.LoggingServlet.java
/** * Get a sorted map with sets "logger name" => <code>LoggerLevelInfo</code> * @return SortedMap<String, LoggerLevelInfo> *//* w ww . java 2 s . co m*/ private SortedMap<String, LoggerLevelInfo> getLoggerLevelInfosMap() { SortedMap<String, LoggerLevelInfo> loggerLevelInfosMap = new TreeMap<String, LoggerLevelInfo>(); if (isJDK14Log) { java.util.logging.LogManager manager = java.util.logging.LogManager.getLogManager(); for (Enumeration<String> namesIter = manager.getLoggerNames(); namesIter.hasMoreElements();) { String loggerName = namesIter.nextElement(); java.util.logging.Logger logger = manager.getLogger(loggerName); java.util.logging.Level level = logger.getLevel(); java.util.logging.Level effectiveLevel = level; // try to find effective level if (level == null) { for (java.util.logging.Logger l = logger; l != null; l = l.getParent()) { if (l.getLevel() != null) { effectiveLevel = l.getLevel(); break; } } } if (level != null) { loggerLevelInfosMap.put(loggerName, new LoggerLevelInfo(loggerName, level.toString())); } else { loggerLevelInfosMap.put(loggerName, new LoggerLevelInfo(loggerName, null, effectiveLevel.toString())); } } } else if (isLog4jLog) { try { // Log4j Classes Class<?> loggerClass = Class.forName("org.apache.log4j.Logger"); Class<?> managerClass = Class.forName("org.apache.log4j.LogManager"); // Log4j Methods Method getName = loggerClass.getMethod("getName", null); Method getLevel = loggerClass.getMethod("getLevel", null); Method getEffectiveLevel = loggerClass.getMethod("getEffectiveLevel", null); Method getLoggers = managerClass.getMethod("getCurrentLoggers", null); // get and sort loggers and log levels Enumeration loggers = (Enumeration) getLoggers.invoke(null, null); while (loggers.hasMoreElements()) { try { Object logger = loggers.nextElement(); String loggerName = (String) getName.invoke(logger, null); Object level = getLevel.invoke(logger, null); Object effectiveLevel = getEffectiveLevel.invoke(logger, null); if (level != null) { loggerLevelInfosMap.put(loggerName, new LoggerLevelInfo(loggerName, level.toString())); } else { loggerLevelInfosMap.put(loggerName, new LoggerLevelInfo(loggerName, null, effectiveLevel.toString())); } } catch (Exception e) { log.error("Error getting logger name and level : " + e.getMessage()); } } } catch (Exception e) { log.error("Error getting log4j through reflection: " + e.getMessage(), e); } } return loggerLevelInfosMap; }