|
||||||||||||
|
|
| log4j的辅助代码,支持合并多个log4j配置文件。 |
| 时间:22/04/2007 作者:网络 来源:网络 |
| 小提示→点这里把文章加入您的收藏夹,方便下次查看 |
| 设置文章字体大小:[大 中 小] |
|
1。当多人合作开发程序时,都使用了log4j,而且各自写了各自的log4j,properties配置文件 ,
在程序合并的时候,如果要合并配置文件的话,在后期开发维护又会产生一些不便。 //copyright © li zong bo
而log4j自身的配置信息,在读取新配置文件的时候,老配置文件的信息不会叠加。
因此自己写了个下面的方法。用来兼容老的配置信息的读取,也增强了配置文件的灵活性。
使用方法,只要配置文件名字满足log4j*.properties,再指定配置文件存放的文件夹就可以了。
/*
import org.apache.log4j.PropertyConfigurator; PropertyConfigurator.configure(Properties properties);
使用这个方法来调用即可。 //copyright © li zongbo
*/
public static Properties loadproperties(String dir)
throws FileNotFoundException, IOException { return loadproperties(dir, null); } public static Properties loadproperties(String dir, String fileNamestartWith)
throws FileNotFoundException, IOException { if (fileNamestartWith == null) { fileNamestartWith = "log4j"; } Properties pro = new Properties();
File fdir = new File(dir); if (fdir.isFile()) {
if (fdir.getName().toLowerCase().endsWith(".properties")) { pro.load(new FileInputStream(fdir)); } } else { File[] fspro = fdir.listFiles(); for (int i = 0; i < fspro.length; i++) { //copyright © lizongbo
if (fspro[i].getName().startsWith(fileNamestartWith) && fspro[i].getName().toLowerCase().endsWith(".properties")) { Properties temppro = new Properties(); temppro.load(new FileInputStream(fspro[i])); for (Enumeration e = temppro.keys(); e.hasMoreElements();) { //copyright © lizongbo
String key = (String) e.nextElement(); pro.setProperty(key, temppro.getProperty(key)); } } } } return pro;
} |
|
上一篇:随机数的困惑(java.util.Random/Math.Random()
下一篇:log4j的辅助代码,支持合并多个log4j配置文件。 |
| 【返回】 【顶部】 【关闭】 |
| Copyright © 2005-2010 www.594k.com All Rights Reserved. |
| 版权所有:JAVA学习网
备案序号:皖ICP备06004238号 |