我使用netfishs 6.7.1和glassfish v2.1编写了一个Web服务项目,将log4j.properties放入项目的根目录并使用:
static Logger logger = Logger.getLogger(MyClass.class);
在构造函数中:
PropertyConfigurator.configure("log4j.properties");
在功能上:
logger.info("..."); logger.error("..."); // ...
但是,这是错误信息(实际上,我已经尝试将它几乎可以实现的每个目录都放入):
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.
我知道回答这个问题有点晚了,也许您已经找到了解决方案,但是我将发布我找到的解决方案(在我进行大量Google搜索之后),因此可能会有所帮助:
-Dlog4j.debug