org.apache.log4j.Hierarchy类的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(9.5k)|赞(0)|评价(0)|浏览(271)

本文整理了Java中org.apache.log4j.Hierarchy类的一些代码示例,展示了Hierarchy类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Hierarchy类的具体详情如下:
包路径:org.apache.log4j.Hierarchy
类名称:Hierarchy

Hierarchy介绍

[英]This class is specialized in retrieving loggers by name and also maintaining the logger hierarchy.

The casual user does not have to deal with this class directly.

The structure of the logger hierarchy is maintained by the #getLogger method. The hierarchy is such that children link to their parent but parents do not have any pointers to their children. Moreover, loggers can be instantiated in any order, in particular descendant before ancestor.

In case a descendant is created before a particular ancestor, then it creates a provision node for the ancestor and adds itself to the provision node. Other descendants of the same ancestor add themselves to the previously created provision node.
[中]此类专门用于按名称检索记录器,并维护记录器层次结构。
临时用户不必直接处理此类
记录器层次结构由#getLogger方法维护。层次结构是这样的:子对象链接到其父对象,但父对象没有指向其子对象的任何指针。此外,记录器可以按任何顺序实例化,特别是先于祖先的后代。
如果子代是在特定祖先之前创建的,那么它将为该祖先创建一个供应节点,并将自身添加到供应节点。同一祖先的其他后代将自己添加到先前创建的供应节点。

代码示例

代码示例来源:origin: log4j/log4j

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();
  }
 }
}

代码示例来源:origin: log4j/log4j

/**
  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);
}

代码示例来源:origin: log4j/log4j

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);

代码示例来源:origin: log4j/log4j

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();

代码示例来源:origin: log4j/log4j

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;

代码示例来源:origin: camunda/camunda-bpm-platform

/**
  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();
}

代码示例来源:origin: log4j/log4j

/**
  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();
}

代码示例来源:origin: camunda/camunda-bpm-platform

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();
  }
 }
}

代码示例来源:origin: com.ironoreserver/com.ironoreserver.common

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");
}

代码示例来源:origin: org.terracotta/terracotta-l1-ee

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());
}

代码示例来源:origin: log4j/log4j

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;
 }
}

代码示例来源:origin: camunda/camunda-bpm-platform

/**
  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();
}

代码示例来源:origin: Alluxio/alluxio

Hierarchy clientHierarchy = new Hierarchy(new RootLogger(level));

代码示例来源:origin: log4j/log4j

/**
 *  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);
   }
  }
}

代码示例来源:origin: camunda/camunda-bpm-platform

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();

代码示例来源:origin: log4j/log4j

/**
  @deprecated Please use {@link #getCurrentLoggers} instead.
 */
public
Enumeration getCurrentCategories() {
 return getCurrentLoggers();
}

代码示例来源:origin: log4j/log4j

/**
  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.");
 }
}

代码示例来源:origin: com.ironoreserver/com.ironoreserver.common

@Override
  public void run() {
    defaultLoggerRepository.shutdown();
  }
});

代码示例来源:origin: apache/log4j

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;

代码示例来源:origin: org.apache.log4j/com.springsource.org.apache.log4j

/**
  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();
}

相关文章