我正在尝试使用log4j在我的tomcat安装上的不同文件上记录某些消息,但是虽然它确实登录了我的rootLogger但它并没有在我正在创建的单独文件上执行此操作。
这是我的log4j.properies文件,我正在尝试使用的文件是dataflow_logging.log:
# Root logger option
log4j.rootLogger=INFO, stdout, mainlogger
# Direct dataflow specific messages to specific file.
log4j.logger.org.estat.nsiws.dataflows=INFO, dataflowlogger
log4j.appender.dataflowlogger=org.apache.log4j.RollingFileAppender
log4j.appender.dataflowlogger.File=${catalina.home}/logs/nsi/dataflow_logging.log
log4j.appender.dataflowlogger.MaxFileSize=10MB
log4j.appender.dataflowlogger.MaxBackupIndex=10
log4j.appender.dataflowlogger.layout=org.apache.log4j.PatternLayout
log4j.appender.dataflowlogger.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
# Disable dataflow log messages in root logger.
log4j.additivity.org.estat.nsiws.dataflows=false
# Direct main logging messages to standard output.
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{HH:mm:ss,SSS} [%p]: %m%n
# Also direct main logging messages to file.
log4j.appender.mainlogger=org.apache.log4j.RollingFileAppender
log4j.appender.mainlogger.File=${catalina.home}/logs/nsi/nsiws.log
log4j.appender.mainlogger.MaxFileSize=10MB
log4j.appender.mainlogger.MaxBackupIndex=10
log4j.appender.mainlogger.layout=org.apache.log4j.PatternLayout
log4j.appender.mainlogger.layout.ConversionPattern=%d{HH:mm:ss,SSS} [%p]: %m%n
我的WebService的属性文件:
## This file contains properties for the Web Service
# The absolute path to the logs directory
log.directory=logs/nsi
# The log file prefix
log.file.prefix=nsiws_
# The log file suffix
log.file.suffix=.log
# The prefix of the temporary files created for the buffering of responses.
tempfile.buffer.prefix=ws_resp
# Enable logging dataflow access
log.df.file.activation=true
# The absolute path to the dataflow logs directory
log.df.file.directory=logs/nsi
# The dataflow log file prefix
log.df.file.name=dataflow_logging
# The dataflow log file maximum size
log.df.file.max.size=100MB
# The dataflow max backup file
log.df.file.max.backup=10
# The dataflow log file separator
log.df.file.separator=;
# The dataflow log file date pattern
log.df.date.pattern=%d{yyyy-MM-dd HH:mm:ss,SSS};%m%n
初始化数据流记录器的方法:
private static Logger initDataflowLogger() {
Logger dflogger = null;
try {
if (Boolean.parseBoolean(nsiProps.getProperty("log.df.file.activation"))) {
dflogger = org.apache.log4j.Logger.getLogger("org.estat.nsiws.dataflows");
dflogger.setLevel(Level.INFO);
logger.debug("Initializing dataflow logging...");
}
} catch (Exception e) {
logger.error(getInstance().getMessage("error.df.log.properties.not.set"));
}
return dflogger;
}
非常感谢你的帮助!
答案 0 :(得分:1)
检查此表达式是否为true,以及是否正确设置了属性文件,以便项目可以从中读取。
Boolean.parseBoolean(nsiProps.getProperty("log.df.file.activation"))
答案 1 :(得分:0)