I have a persistent event-driven HTTP upload program (hot folder) that writes to a log on every action. It runs indefinitely until the user decides to close it.
To ensure the log is closed when the application is closed, I have written the program so on every write to log, it opens the log file, writes to it, and then closes the log.
Like so:
fh = new FileHandler(logName, true);
fh.setFormatter(new MyCustomFormatter());
logger.addHandler(fh);
logger.info(message);
logger.removeHandler(fh);
fh.close();
Recently, I have considered reducing the number of open/closes by opening the log for the duration of an upload job (potentially hundreds of writes to the log) and then closing when the job is done.
Long story short, how much of a performance gain would I expect from this? Are there other options to ensuring the application closes without an unclosed log file?