log4j读取配置文件错误

时间:2013-10-17 18:19:12

标签: java tomcat logging

我在Tomcat中部署了java Web应用程序。我在WEB-INF下创建了一个classes文件夹,并在其下面有log4j.properties文件。我希望将记录器附加到文件中。

log4j.properties文件:

log4j.rootLogger=DEBUG, CA

# AdminFileAppender - used to log messages in the admin.log file.
log4j.appender.AdminFileAppender=org.apache.log4j.FileAppender
log4j.appender.AdminFileAppender.File=admin.log
log4j.appender.AdminFileAppender.layout=org.apache.log4j.PatternLayout
log4j.appender.AdminFileAppender.layout.ConversionPattern= %-4r [%t] %-5p %c %x - %m%n

# ReportFileAppender - used to log messages in the report.log file.
log4j.appender.ReportFileAppender=org.apache.log4j.FileAppender

log4j.appender.ReportFileAppender.File=report.log
log4j.appender.ReportFileAppender.layout=org.apache.log4j.PatternLayout
log4j.appender.ReportFileAppender.layout.ConversionPattern= %-4r [%t] %-5p %c %x - %m%n

# ConsoleAppender
log4j.appender.CA=org.apache.log4j.ConsoleAppender
log4j.appender.CA.layout=org.apache.log4j.PatternLayout
log4j.appender.CA.layout.ConversionPattern= %-4r [%t] %-5p %c %x - %m%n

log4j.logger.com.sample.cfd=WARN,AdminFileAppender 
log4j.logger.com.sample.cfd=DEBUG,ReportFileAppender 

Servlet中的代码

 private static Logger logger = Logger.getLogger(CfdServlet.class);
 dpPost(...){
     PropertyConfigurator.configure("log4j.properties");
     logger.debug("Sample debug message");
 }

错误消息:

我收到以下错误,因为它无法在 WEB_INF / classes / log4j.properties

下找到我的配置文件
log4j:ERROR Could not read configuration file [log4j.properties].
java.io.FileNotFoundException: log4j.properties (No such file or directory)

我的属性文件的位置有问题。

0 个答案:

没有答案