我正在使用 java 处理文件,有 2 或 3 个 Java 组件来处理文件。我的要求是文件必须有一个日志文件,其处理细节将记录在相关的日志文件中。
问题是对于单个文件,它运行良好,但对于多个文件却出现问题。当处理多个文件时,记录器将 file1.txt 日志的日志详细信息记录到 file2.log 而不是 file1.log...
public Class FileProcessComponent1
{
public void process(String fileName)
{
Logger Log = Logg.getLogger1(fileName,this.getClass());
log.info("file1 logging");
}
}
public Class FileProcessComponent2
{
public void process(String fileName)
{
Logger Log = Logg.getLogger1(fileName,this.getClass());
log.info("file1 logging");
}
}
public Class Logg
{
public static Logger getLogger1(String fileName,Class clazz) throws Exception
{
if(fileName == null || "".equals(fileName.trim()))
throw new Exception("File Name or Map for File Name is Null");
fileName = "/home/logs/"+fileName+".log";
Logger logger = Logger.getLogger(clazz.getCanonicalName()+":"+System.nanoTime());
logger.setAdditivity(false);
FileAppender appender = new DailyRollingFileAppender(new PatternLayout("%d{ISO8601}\t%p\t%c\t%m%n"), fileName, "'.'yyyy-MM-dd");
logger.addAppender(appender);
logger.setLevel(Level.DEBUG);
return logger;
}
}