public void setAppend(boolean append) {
this.append = append;
}
private void safeWrite(E event) throws IOException {
ResilientFileOutputStream resilientFOS = (ResilientFileOutputStream) getOutputStream();
FileChannel fileChannel = resilientFOS.getChannel();
if (fileChannel == null) {
return;
}
// Clear any current interrupt (see LOGBACK-875)
boolean interrupted = Thread.interrupted();
FileLock fileLock = null;
try {
fileLock = fileChannel.lock();
long position = fileChannel.position();
long size = fileChannel.size();
if (size != position) {
fileChannel.position(size);
}
super.writeOut(event);
} catch (IOException e) {
// Mainly to catch FileLockInterruptionExceptions (see LOGBACK-875)
resilientFOS.postIOFailure(e);
}
finally {
if (fileLock != null) {
fileLock.release();
}