我有一个为个人客户运行的程序。每个客户都有一个帐户代码(我们称之为起始代码)。帐户代码通过命令行参数传递给程序。我收到了以下异常,顺便说一句,它不会导致程序崩溃,它会顺利进行。我想按客户帐户分开记录,这似乎有效。我的日志文件将被创建为“Balancer_990004.log”,并且日志消息肯定会建立到创建 Balancer_990004.log.7 的点,但是,并非没有这个例外。在这个上挠头。我已经包含了 log4j.properties 位和代码位。
log4j:ERROR setFile(null,true) call failed.
java.io.FileNotFoundException: (A file or directory in the path name does not exist.)
at java.io.FileOutputStream.openAppend(Native Method)
at java.io.FileOutputStream.<init>(FileOutputStream.java:203)
at java.io.FileOutputStream.<init>(FileOutputStream.java:127)
at org.apache.log4j.FileAppender.setFile(FileAppender.java:294)
at org.apache.log4j.RollingFileAppender.setFile(RollingFileAppender.java:207)
at org.apache.log4j.FileAppender.activateOptions(FileAppender.java:165)
at org.apache.log4j.config.PropertySetter.activate(PropertySetter.java:307)
at org.apache.log4j.config.PropertySetter.setProperties(PropertySetter.java:172)
at org.apache.log4j.config.PropertySetter.setProperties(PropertySetter.java:104)
at org.apache.log4j.PropertyConfigurator.parseAppender(PropertyConfigurator.java:809)
at org.apache.log4j.PropertyConfigurator.parseCategory(PropertyConfigurator.java:735)
at org.apache.log4j.PropertyConfigurator.parseCatsAndRenderers(PropertyConfigurator.java:639)
at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:504)
at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:547)
at org.apache.log4j.helpers.OptionConverter.selectAndConfigure(OptionConverter.java:483)
at org.apache.log4j.LogManager.<clinit>(LogManager.java:127)
at java.lang.J9VMInternals.initializeImpl(Native Method)
at java.lang.J9VMInternals.initialize(J9VMInternals.java:200)
at org.apache.log4j.Logger.getLogger(Logger.java:117)
at Balancer.<init>(Balancer.java:292)
at Balancer.main(Balancer.java:2370)
*** Sample bit from log4j.properties. The name of the Java program in question is "Balancer" ***
log4j.rootLogger=debug, devnull
log4j.logger.Balancer=info, BalancerLog
log4j.appender.BalancerLog=org.apache.log4j.RollingFileAppender
log4j.appender.BalancerLog.File=${balancer.log}
log4j.appender.BalancerLog.MaxFileSize=10000KB
log4j.appender.BalancerLog.MaxBackupIndex=10
log4j.appender.BalancerLog.layout=org.apache.log4j.PatternLayout
log4j.appender.BalancerLog.layout.ConversionPattern=%5p %d [%t] (%F:%L) - %m%n
*** How I'm building my log filename and initializing the Logger ***
public class Balancer {
static Logger log = null;
....
// In constructor...
StringBuilder logName = new StringBuilder("Balancer_");
logName.append(startCode.toString());
logName.append(".log");
// Hopefully in log4j.properties our appender section contains this line:
// log4j.appender.BalancerLog.File=${balancer.log}. This ${} bit means to get a system property to set the log file
// name. We set that system property here, then initialize the Logger object.
System.setProperty("balancer.log", logName.toString());
// This is line 292 in the exception trace.
log = Logger.getLogger(Balancer.class);