LoggerRepository configureHierarchy(InetAddress inetAddress) { cat.info("Locating configuration file for "+inetAddress); // We assume that the toSting method of InetAddress returns is in // the format hostname/d1.d2.d3.d4 e.g. torino/192.168.1.1 String s = inetAddress.toString(); int i = s.indexOf("/"); if(i == -1) { cat.warn("Could not parse the inetAddress ["+inetAddress+ "]. Using default hierarchy."); return genericHierarchy(); } else { String key = s.substring(0, i); File configFile = new File(dir, key+CONFIG_FILE_EXT); if(configFile.exists()) { Hierarchy h = new Hierarchy(new RootLogger(Level.DEBUG)); hierarchyMap.put(inetAddress, h); new PropertyConfigurator().doConfigure(configFile.getAbsolutePath(), h); return h; } else { cat.warn("Could not find config file ["+configFile+"]."); return genericHierarchy(); } } }
/** Return a new logger instance named as the first parameter using the default factory. <p>If a logger of that name already exists, then it will be returned. Otherwise, a new logger will be instantiated and then linked with its existing ancestors as well as children. @param name The name of the logger to retrieve. */ public Logger getLogger(String name) { return getLogger(name, defaultFactory); }
void resetConfiguration() { getRootLogger().setLevel((Level) Level.DEBUG); root.setResourceBundle(null); setThreshold(Level.ALL); shutdown(); // nested locks are OK Enumeration cats = getCurrentLoggers(); while(cats.hasMoreElements()) { Logger c = (Logger) cats.nextElement(); c.setLevel(null); c.setAdditivity(true); c.setResourceBundle(null);
Logger root = getRootLogger(); root.closeNestedAppenders(); Enumeration cats = this.getCurrentLoggers(); while(cats.hasMoreElements()) { Logger c = (Logger) cats.nextElement(); c.closeNestedAppenders(); root.removeAllAppenders(); cats = this.getCurrentLoggers(); while(cats.hasMoreElements()) { Logger c = (Logger) cats.nextElement();
Object o = ht.get(key); if(o == null) { logger = factory.makeNewLoggerInstance(name); logger.setHierarchy(this); ht.put(key, logger); updateParents(logger); return logger; } else if(o instanceof Logger) { logger.setHierarchy(this); ht.put(key, logger); updateChildren((ProvisionNode) o, logger); updateParents(logger); return logger;
/** Create a new logger hierarchy. @param root The root of the new hierarchy. */ public Hierarchy(Logger root) { ht = new Hashtable(); listeners = new Vector(1); this.root = root; // Enable all level levels by default. setThreshold(Level.ALL); this.root.setHierarchy(this); rendererMap = new RendererMap(); defaultFactory = new DefaultCategoryFactory(); }
/** Create a new logger hierarchy. @param root The root of the new hierarchy. */ public Hierarchy(Logger root) { ht = new Hashtable(); listeners = new Vector(1); this.root = root; // Enable all level levels by default. setThreshold(Level.ALL); this.root.setHierarchy(this); rendererMap = new RendererMap(); defaultFactory = new DefaultCategoryFactory(); }
LoggerRepository configureHierarchy(InetAddress inetAddress) { cat.info("Locating configuration file for "+inetAddress); // We assume that the toSting method of InetAddress returns is in // the format hostname/d1.d2.d3.d4 e.g. torino/192.168.1.1 String s = inetAddress.toString(); int i = s.indexOf("/"); if(i == -1) { cat.warn("Could not parse the inetAddress ["+inetAddress+ "]. Using default hierarchy."); return genericHierarchy(); } else { String key = s.substring(0, i); File configFile = new File(dir, key+CONFIG_FILE_EXT); if(configFile.exists()) { Hierarchy h = new Hierarchy(new RootLogger((Level) Priority.DEBUG)); hierarchyMap.put(inetAddress, h); new PropertyConfigurator().doConfigure(configFile.getAbsolutePath(), h); return h; } else { cat.warn("Could not find config file ["+configFile+"]."); return genericHierarchy(); } } }
protected void populateMDC() { ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); if (classLoader != null) { if (classLoader.getClass().getName().equalsIgnoreCase("com.ironore.core.WebAppClassLoader")) { Method method = null; try { method = classLoader.getClass().getDeclaredMethod("contextPath"); method.setAccessible(true); Object contextPath = method.invoke(classLoader); MDC.put("ironore_contextPath", contextPath); } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) { defaultHierarchy.getLogger(Logger.class.getName()).error("unable to get context path through reflection", e); } return; } } MDC.put("ironore_contextPath", "server"); }
private void resolveClasses() { // This is to help a deadlock in log4j (see MNK-3461, MNK-3512) Logger l = new RootLogger(Level.ALL); Hierarchy h = new Hierarchy(l); l.addAppender(new WriterAppender(new PatternLayout(TCLogging.FILE_AND_JMX_PATTERN), new OutputStream() { @Override public void write(int b) { // } })); l.debug(h.toString(), new Throwable()); }
LoggerRepository genericHierarchy() { if(genericHierarchy == null) { File f = new File(dir, GENERIC+CONFIG_FILE_EXT); if(f.exists()) { genericHierarchy = new Hierarchy(new RootLogger(Level.DEBUG)); new PropertyConfigurator().doConfigure(f.getAbsolutePath(), genericHierarchy); } else { cat.warn("Could not find config file ["+f+ "]. Will use the default hierarchy."); genericHierarchy = LogManager.getLoggerRepository(); } } return genericHierarchy; } }
/** Reset all values contained in this hierarchy instance to their default. This removes all appenders from all categories, sets the level of all non-root categories to <code>null</code>, sets their additivity flag to <code>true</code> and sets the level of the root logger to {@link Level#DEBUG DEBUG}. Moreover, message disabling is set its default "off" value. <p>Existing categories are not removed. They are just reset. <p>This method should be used sparingly and with care as it will block all logging until it is completed.</p> @since 0.8.5 */ public void resetConfiguration() { getRootLogger().setLevel((Level) Level.DEBUG); root.setResourceBundle(null); setThreshold(Level.ALL); // the synchronization is needed to prevent JDK 1.2.x hashtable // surprises synchronized(ht) { shutdown(); // nested locks are OK Enumeration cats = getCurrentLoggers(); while(cats.hasMoreElements()) { Logger c = (Logger) cats.nextElement(); c.setLevel(null); c.setAdditivity(true); c.setResourceBundle(null); } } rendererMap.clear(); }
Hierarchy clientHierarchy = new Hierarchy(new RootLogger(level));
/** * LoggerRepository forgot the fireRemoveAppenderEvent method, * if using the stock Hierarchy implementation, then call its fireRemove. * Custom repositories can implement HierarchyEventListener if they * want remove notifications. * @param appender appender, may be null. */ private void fireRemoveAppenderEvent(final Appender appender) { if (appender != null) { if (repository instanceof Hierarchy) { ((Hierarchy) repository).fireRemoveAppenderEvent(this, appender); } else if (repository instanceof HierarchyEventListener) { ((HierarchyEventListener) repository).removeAppenderEvent(this, appender); } } }
Logger root = getRootLogger(); Enumeration cats = this.getCurrentLoggers(); while(cats.hasMoreElements()) { Logger c = (Logger) cats.nextElement(); cats = this.getCurrentLoggers(); while(cats.hasMoreElements()) { Logger c = (Logger) cats.nextElement();
/** @deprecated Please use {@link #getCurrentLoggers} instead. */ public Enumeration getCurrentCategories() { return getCurrentLoggers(); }
/** The string form of {@link #setThreshold(Level)}. */ public void setThreshold(String levelStr) { Level l = (Level) Level.toLevel(levelStr, null); if(l != null) { setThreshold(l); } else { LogLog.warn("Could not convert ["+levelStr+"] to Level."); } }
@Override public void run() { defaultLoggerRepository.shutdown(); } });
Object o = ht.get(key); if(o == null) { logger = factory.makeNewLoggerInstance(name); logger.setHierarchy(this); ht.put(key, logger); updateParents(logger); return logger; } else if(o instanceof Logger) { logger.setHierarchy(this); ht.put(key, logger); updateChildren((ProvisionNode) o, logger); updateParents(logger); return logger;
/** Create a new logger hierarchy. @param root The root of the new hierarchy. */ public Hierarchy(Logger root) { ht = new Hashtable(); listeners = new Vector(1); this.root = root; // Enable all level levels by default. setThreshold(Level.ALL); this.root.setHierarchy(this); rendererMap = new RendererMap(); defaultFactory = new DefaultCategoryFactory(); }