我在 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)
我的属性文件的位置有问题。