I am working on a web application and I have a requirement to create runtime log files for my impex process. Here is an example of use. I check the XML file, and the check error is handled by a special error handler. This hanlde error will be passed to the base validator (Jaxb 2.x validator), so I need to create a log file when an instance of this hanlder error is created. we use log4j as a logging API
here is the code to create the log file at runtime
XMLErrorHandler<Object> errorHandler=new XMLErrorHandler<Object>(logFileLocation); logFileName=errorHandler.getLogFileName(); validator.setErrorHandler(errorHandler); validator.validate(source);
I am creating a log file inside the XMLErrorHandler constructor, since this is the only point I have control at, is the code to create the log file.
FileAppender appender; try { appender = new FileAppender(layout, sb.toString(), false); log.addAppender(appender); log.setAdditivity(false); log.setLevel(Level.WARN); } catch (IOException e) { e.printStackTrace(); }
everything works fine, and the file is created correctly and recorded by the registrar in the appropriate place. but if I restart my server, the real problem will start, and the registrar will begin to add the contents of the log not only to the current log file, but to the entire file created for this process during server operation. Here are the details, which suggests that I have 3 log files (A, B, C) already in place with 3 lines in each log file, and C is the last file created in this process. so when I restart my server (by renaming, I mean that I stopped tomcat from the console), some of them, like adding data to all previous log files in this fashin C has 3 more lines B has now 6 lines A has now 9 lines
It seems that the appender I created is still open or has a refrence, not sure what exactly is happening. any help in this regard would be helpful.
java logging tomcat6 log4j
Umesh awasthi
source share