Well, one issue is here:
try {
fh = new FileHandler(file.getPath(), append);
fh.setFormatter(new Formatter() {
@Override
public String format(LogRecord record) {
return "[test] " + "[" + record.getLevel().toString() + "]" + String.format(record.getMessage(), record.getParameters()) + newline;
}
});
return new FileHandler(file.getPath(), append);
} catch (Exception e) {
if (fh != null)
fh.close();
return null;
You never close the file in the try statement, only closing it if there is an error. You should close the file as soon as you done with it:
try {
fh = new FileHandler(file.getPath(), append);
fh.setFormatter(new Formatter() {
@Override
public String format(LogRecord record) {
return "[test] " + "[" + record.getLevel().toString() + "]" + String.format(record.getMessage(), record.getParameters()) + newline;
}
});
//close fh
fh.close();
return new FileHandler(file.getPath(), append);
} catch (Exception e) {
if (fh != null)
fh.close();
return null;