我应该把 log4j.properties 文件放在哪里? [英] Where should I put the log4j.properties file?

查看:49
本文介绍了我应该把 log4j.properties 文件放在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 netbeans 6.7.1 和 glassfish v2.1 编写了一个 web 服务项目,将 log4j.properties 放到项目的根目录并使用:

I wrote a web service project using netbeans 6.7.1 with glassfish v2.1, put log4j.properties to the root dir of project and use:

static Logger logger = Logger.getLogger(MyClass.class);

在构造函数中:

PropertyConfigurator.configure("log4j.properties");

在函数中:

logger.info("...");
logger.error("...");
// ...

但是,这是错误信息(实际上,我已经尝试将它放在几乎所有我能意识到的目录中):

but, it is error info(actually, I have tried to put it almost every dir that I could realize):

log4j:ERROR Could not read configuration file [log4j.properties].
java.io.FileNotFoundException: log4j.properties (The system cannot find the file specified)
        at java.io.FileInputStream.open(Native Method)
        at java.io.FileInputStream.<init>(FileInputStream.java:106)
        at java.io.FileInputStream.<init>(FileInputStream.java:66)
        at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:297)
        at org.apache.log4j.PropertyConfigurator.configure(PropertyConfigurator.java:315)
        at com.corp.ors.demo.OrsDemo.main(OrisDemo.java:228)
log4j:ERROR Ignoring configuration file [log4j.properties].
log4j:WARN No appenders could be found for logger (com.corp.ors.demo.OrsDemo).
log4j:WARN Please initialize the log4j system properly.

示例项目可以从 http://www.91files.com/?N3F0QGQPWMDGPBRN0QA8 获得

the example project could be get from http://www.91files.com/?N3F0QGQPWMDGPBRN0QA8

推荐答案

我知道现在回答这个问题有点晚了,也许你已经找到了解决方案,但我正在发布我找到的解决方案(在我搜索了一个很多)所以它可能会有所帮助:

I know it's a bit late to answer this question, and maybe you already found the solution, but I'm posting the solution I found (after I googled a lot) so it may help a little:

  1. 将 log4j.properties 放在项目的 WEB-INFclasses 下,如本线程前面所述.
  2. 将 log4j-xx.jar 放在 WEB-INFlib 下
  3. 测试是否加载了log4j:添加-Dlog4j.debug@tomcat的java选项的末尾
  1. Put log4j.properties under WEB-INFclasses of the project as mentioned previously in this thread.
  2. Put log4j-xx.jar under WEB-INFlib
  3. Test if log4j was loaded: add -Dlog4j.debug @ the end of your java options of tomcat

希望这会有所帮助.

rgds

这篇关于我应该把 log4j.properties 文件放在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆