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

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

问题描述

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

 静态记录器记录器= Logger.getLogger(MyClass.class); 

在构造函数中:

  PropertyConfigurator.configure( log4j.properties); 

以及函数:

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

但是,它是错误信息(实际上,我试过了几乎所有可以实现的目录):

  log4j:ERROR无法读取配置文件[log4j.properties]。 
java.io.FileNotFoundException:log4j.properties(系统找不到指定的文件)
在java.io.FileInputStream.open(Native Method)
在java.io.FileInputStream。< (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:错误忽略配置文件[log4j.properties]。
log4j:WARN记录器没有找到appender(com.corp.ors.demo.OrsDemo)。
log4j:WARN请正确初始化log4j系统。

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

解决方案

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


  1. 将log4j.properties放置在项目的WEB-INF \ classes下,如前面在此线程中提到的。
  2. 将log4j-在WEB-INF \ lib下的xx.jar
  3. 测试log4j是否已加载:add -Dlog4j.debug @ Tomcat的java选项

希望这会对您有所帮助。 $ b

rgds p>

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

in Constructor:

PropertyConfigurator.configure("log4j.properties");

and in functions:

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.

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. Put log4j.properties under WEB-INF\classes of the project as mentioned previously in this thread.
  2. Put log4j-xx.jar under WEB-INF\lib
  3. Test if log4j was loaded: add -Dlog4j.debug @ the end of your java options of tomcat

Hope this will help.

rgds

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

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