Hello Lesley,
Thank you for the test case.
Indeed, multiple FileAppender instances located in the same JVM and writing to
the same file is a source of error. Just use a single FileAppender instance per
file target.
AsyncAppender uses references to appenders. It does not create them on its own.
So, in principle, using AsyncAppender should not be a problem.
Lesley Tay wrote:
Hi Ceki,
We actually did a bit more investigation into that same possibility and found
that if you have
a test class similar to the one below:
import java.io.File;
import java.io.FileWriter;
public class FileTest {
public static void main(String args[]) throws Exception {
File file1 = new File("test.file");
FileWriter writer1 = new FileWriter(file1);
for (int i = 0 ; i < 20 ; i++) {
writer1.write("Step 1 \n");
}
writer1.flush();
FileWriter writer2 = new FileWriter(file1);
for (int i = 0 ; i < 10 ; i++) {
writer2.write("Step 2 \n");
}
writer2.flush();
writer2.close();
for (int i = 0 ; i < 20 ; i++) {
writer1.write("Step 3 \n");
}
writer1.flush();
writer1.close();
}
}
We see null characters in the log. Seems to suggest perhaps we either have 2 threads writing to the file as you suggested,
or two logical files open on the same physical file. When the second file is
open (writer2) the phisical file is filled with null characters up to current
end of file1. Then writer2 starts writing from the beginnig (overwritting some
of the nulls with new information) and writer1 continues to appending after
what it belives is the end of the file.
This is quite odd especially considering that we use AsyncAppenders (which open the files).
Regards,
Lesley
--
Ceki Gülcü
Logback: The reliable, generic, fast and flexible logging framework for Java.
http://logback.qos.ch
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]