0

为什么我的第二个记录器出错但第一个没有?

错误:

log4j:WARN No appenders could be found for logger (StatQueryDobadoCategory).
log4j:WARN Please initialize the log4j system properly.

这是 log4j.properties:

log4j.category.ThingsPerMinuteGraphCategory=DEBUG, ThingsPerMinuteGraphAppender
log4j.appender.ThingsPerMinuteGraphAppender=org.apache.log4j.RollingFileAppender
log4j.appender.ThingsPerMinuteGraphAppender.File=./logs/ThingsPerMinuteGraph.log
log4j.appender.ThingsPerMinuteGraphAppender.MaxFileSize=20MB
log4j.appender.ThingsPerMinuteGraphAppender.MaxBackupIndex=5
log4j.appender.ThingsPerMinuteGraphAppender.layout=org.apache.log4j.PatternLayout
log4j.appender.ThingsPerMinuteGraphAppender.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss.SSS} - %m
log4j.additivity.ThingsPerMinuteGraphCategory=false

log4j.category.StatQueryDobadoCategory=DEBUG, StatQueryDobadoAppender
log4j.appender.StatQueryDobadoAppender=org.apache.log4j.RollingFileAppender
log4j.appender.StatQueryDobadoAppender.File=./logs/StatQueryDobadoCategory.log
log4j.appender.StatQueryDobadoAppender.MaxFileSize=20MB
log4j.appender.StatQueryDobadoAppender.MaxBackupIndex=5
log4j.appender.StatQueryDobadoAppender.layout=org.apache.log4j.PatternLayout
log4j.appender.StatQueryDobadoAppender.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss.SSS} - %m
log4j.additivity.StatQueryDobadoCategory=false
4

1 回答 1

0

库似乎无法访问 log4j.properties。

  1. 如果您仅将 log4j 用于 java 项目,请将属性文件放入源文件夹

  2. 如果你在 j2ee 项目中使用 log4j,比如 spring+hibernate,将 log4j.properties 放入 WEB-INF 文件夹,并在项目的属性文件中设置属性文件的路径

    
    <context-param>
    <param-name>log4jConfigLocation</param-name>
    <param-value>/WEB-INF/log4j.properties</param-value>
    </context-param>
    

于 2012-05-09T05:58:29.257 回答