我在 Windows 2003 服务器 R2 上运行一些 java 进程,我使用的是 Apache log4j-1.2.8。我的所有进程都通过一个具有不同参数示例的 jar 文件调用
java -jar process.jar one
java -jar process.jar two
java -jar process.jar three
我配置 log4j.properties 跟随
#===============================
# Declare Variables
#===============================
logpath=${user.dir}/log/
simple_pattern=%d{yyyy-MM-dd HH:mm:ss.SSS}%-5x - %m%n
backup_pattern='.'yyyy-MM-dd
#===============================
# PROCESS & STANDARD OUTPUT
#===============================
log4j.logger.process.Process=NULL,proclog,procstdout
log4j.appender.proclog=org.apache.log4j.DailyRollingFileAppender
log4j.appender.proclog.File=${logpath}process.log
log4j.appender.proclog.DatePattern=${backup_pattern}
log4j.appender.proclog.layout=org.apache.log4j.PatternLayout
log4j.appender.proclog.layout.conversionPattern=${simple_pattern}
log4j.appender.procstdout=org.apache.log4j.ConsoleAppender
log4j.appender.procstdout.layout=org.apache.log4j.PatternLayout
log4j.appender.procstdout.layout.ConversionPattern=${simple_pattern}
#===============================
# ONE
#===============================
log4j.logger.process.log.One=NULL,one
log4j.appender.one=org.apache.log4j.DailyRollingFileAppender
log4j.appender.one.File=${logpath}one.log
log4j.appender.one.DatePattern=${backup_pattern}
log4j.appender.one.layout=org.apache.log4j.PatternLayout
log4j.appender.one.layout.conversionPattern=${simple_pattern}
#===============================
# TWO
#===============================
log4j.logger.process.log.Two=NULL,two
log4j.appender.two=org.apache.log4j.DailyRollingFileAppender
log4j.appender.two.File=${logpath}two.log
log4j.appender.two.DatePattern=${backup_pattern}
log4j.appender.two.layout=org.apache.log4j.PatternLayout
log4j.appender.two.layout.conversionPattern=${simple_pattern}
#===============================
# THREE
#===============================
log4j.logger.process.log.Three=NULL,three
log4j.appender.three=org.apache.log4j.DailyRollingFileAppender
log4j.appender.three.File=${logpath}three.log
log4j.appender.three.DatePattern=${backup_pattern}
log4j.appender.three.layout=org.apache.log4j.PatternLayout
log4j.appender.three.layout.conversionPattern=${simple_pattern}
我第一次使用进程附加程序是单个记录器,现在我将它分成一个、两个和三个记录器。我的 Windows 进程每 1 分钟执行一次。
所以。我遇到了大问题,我不知道为什么 log4j 无法生成备份文件。但是当我通过命令行执行手动时就可以了。