本文整理汇总了Java中org.apache.log4j.Hierarchy类的典型用法代码示例。如果您正苦于以下问题:Java Hierarchy类的具体用法?Java Hierarchy怎么用?Java Hierarchy使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Hierarchy类属于org.apache.log4j包,在下文中一共展示了Hierarchy类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: configureHierarchy
import org.apache.log4j.Hierarchy; //导入依赖的package包/类
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();
}
}
}
示例2: init
import org.apache.log4j.Hierarchy; //导入依赖的package包/类
public static synchronized void init(ServletContext servletContext)
throws ServletException {
if (!initialized) // set the global RepositorySelector
{
defaultRepository = LoggerFactory.getLoggerRepository();
RepositorySelector theSelector = new AppRespositorySelector();
LogManager.setRepositorySelector(theSelector, guard);
initialized = true;
}
Hierarchy hierarchy = new Hierarchy(new RootLogger(Level.DEBUG));
loadLog4JConfig(servletContext, hierarchy);
ClassLoader loader = Thread.currentThread().getContextClassLoader();
repositories.put(loader, hierarchy);
}
示例3: loadLog4JConfig
import org.apache.log4j.Hierarchy; //导入依赖的package包/类
private static void loadLog4JConfig(ServletContext servletContext,
Hierarchy hierarchy) throws ServletException {
try {
String log4jFile = "/WEB-INF/log4j.xml";
InputStream log4JConfig = servletContext.getResourceAsStream(log4jFile);
Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(log4JConfig);
DOMConfigurator conf = new DOMConfigurator();
conf.doConfigure(doc.getDocumentElement(), hierarchy);
} catch (Exception e) {
throw new ServletException(e);
}
}