I have an application that scans a set of files. And this scan happens in parallel. I mean, if I upload 5 files, five processes will be created and the job will start in parallel. Now, for registering exceptions for running tasks, there is only one log file. The problem is that logger creates a lot of log files, because -
mylogfile.log(actual log file)
mylogfile.log.1
mylogfile.log.2
mylogfile.log.3
mylogfile.log.4
mylogfile.log.5
...
with their respective lock files. Below is the code snippet that I used:
public static Logger getLogger(final String className) {
final Logger logger = Logger.getLogger(className);
FileHandler fh;
try {
fh = new FileHandler("mylogfile.log", true);
logger.addHandler(fh);
logger.setLevel(Level.ALL);
logger.setUseParentHandlers(false);
fh.setFormatter(new SimpleFormatter());
} catch (final SecurityException e) {
} catch (final IOException e) {
}
return logger;
}
To ensure that you can use only one log file to record exceptions for all jobs running in parallel.
Thanks,
Anish
Anish
source
share