2007-01-12

Log4j 学习日记 - 手工加载配置文件

关键字: log4j
有时候在开发程序的工程中,无法适应application server的log4j加载,必须手工完成这个过程.其代码大约如下:
        URL configFileUrl = LdapUtils.class.getResource("log4j.properties");
        PropertyConfigurator.configure(configFileUrl);

其中,
log4j.properties文件的放置路径为: bin/log4j.properties.如果该文件不是直接放在bin目录下,而是放在某个包中,这里假设是fred.study.configs,那么加载的代码就应该是:
        URL configFileUrl = LdapUtils.class.getResource("/fred/study/configs/log4j.properties");
        PropertyConfigurator.configure(configFileUrl);

加载配置文件的类是LdapUtils
评论
发表评论

您还没有登录,请登录后发表评论

Frederick
搜索本博客
最近加入圈子
存档
最新评论