Here's my code that creates a log file:
// Start a log file
FileHandler fh;
String logFileName = "";
try {
SimpleDateFormat format = new SimpleDateFormat("MM-dd-yyyy_HHmmss");
logFileName = "folder/mylog_" + format.format(Calendar.getInstance().getTime()) + ".log";
fh = new FileHandler(logFileName);
fh.setFormatter(new SimpleFormatter());
logger.addHandler(fh);
logger.setUseParentHandlers(false);
} catch (SecurityException e) {
logger.log(Level.SEVERE, "Exception: ", e);
} catch (IOException e) {
logger.log(Level.SEVERE, "Exception: ", e);
}
Later in my class I need to be able to delete this log file either based on "logFileName" path or the "FileHandler fh".
I tried this "logger.removeHandler(fh);" but it doesn't seem to be working. How can I do that exactly?