Logback with prudent mode creates corrupt log file Logback with prudent mode creates corrupt log file kubernetes kubernetes

Logback with prudent mode creates corrupt log file


Since v1.2.0 the safeWrite is almost useless, if you look into the source code, you can figure it out.

OutputStreamAppender.subAppendprotected void subAppend(E event) {    if (!isStarted()) {        return;    }    try {        // skip some irrelevant codes...        byte[] byteArray = this.encoder.encode(event);        writeBytes(byteArray);    } catch (IOException ioe) {        this.started = false;        addStatus(new ErrorStatus("IO failure in appender", this, ioe));    }}

before v1.2.0 the write logic is like this:

try {    // skip some irrelevant codes...    writeOut(event)} catch (IOException ioe) {    this.started = false;    addStatus(new ErrorStatus("IO failure in appender", this, ioe));}

and the writeOut is Overrided by FileAppender

@Overrideprotected void writeOut(E event) throws IOException {    if (prudent) {        safeWrite(event); // here is the point, it ensure write integrity with file lock    } else {        super.writeOut(event);    }}

This commit was made on Feb 4 2017, check this out.

It's still now misguided in official manual, maybe you can submit an issue in the github repo