我正在尝试将我的信息级别日志和错误级别日志存储在单独的文件中。我的错误消息被正确转储,但信息消息包含错误和信息消息。以下是我的属性文件:
log4j.rootLogger = DEBUG, inf, err
log4j.appender.inf = org.apache.log4j.FileAppender
log4j.appender.inf.layout = org.apache.log4j.PatternLayout
log4j.appender.inf.layout.ConversionPattern = %d{ISO8601} %-5p %c ~ %m%n
log4j.appender.inf.File = information.log
log4j.appender.inf.Threshold = INFO
log4j.appender.inf.filter = org.apache.log4j.varia.LevelMatchFilter
log4j.appender.inf.filter.levelToMatch = INFO
log4j.appender.inf.Append = false
log4j.appender.inf.AcceptOnMatch = true
log4j.appender.inf.filter = org.apache.log4j.varia.DenyAllFilter
log4j.appender.err = org.apache.log4j.FileAppender
log4j.appender.err.layout = org.apache.log4j.PatternLayout
log4j.appender.err.layout.ConversionPattern = %d{ISO8601} %-5p %c ~ %m%n
log4j.appender.err.File = errormsg.log
log4j.appender.err.Threshold = ERROR
log4j.appender.err.filter = org.apache.log4j.varia.LevelMatchFilter
log4j.appender.err.filter.levelToMatch = ERROR
log4j.appender.err.Append = false
我的 .java 文件如下:
package test;
import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
public class HelloLogger {
private static Logger logger = Logger.getLogger(HelloLogger.class);
public static void main(String[] args) {
PropertyConfigurator.configure("log4jconfig.properties");
logger.error("This is error");
logger.info("This is info");
logger.debug("This is debug");
}
}
请帮助.. 提前谢谢