[logback-dev] [JIRA] Created: (LBCORE-158) Interleaved lines in sysout due to synchronization issue with System.out

David Roussel (JIRA) noreply-jira at qos.ch
Fri Jun 11 16:21:16 CEST 2010

Interleaved lines in sysout due to synchronization issue with System.out

                 Key: LBCORE-158
                 URL: http://jira.qos.ch/browse/LBCORE-158
             Project: logback-core
          Issue Type: Bug
          Components: Joran
    Affects Versions: 0.9.20, 0.9.21, 0.9.22
         Environment: java 1.6.0 on Windows XP
            Reporter: David Roussel
            Assignee: Logback dev list

As described in http://stackoverflow.com/questions/2974857/log-back-and-thirdparty-writing-to-stdout-how-to-stop-them-getting-interleaved I've been having problems with both logback and another library both writing to System.out.  Lines from the other library always appear whole, but lines from logback are sometimes broken in two by lines from the other library.

Investigating how writing to console logging works in logback I can see the root of the problem in in ConsileTarget.java.  
The problem seems to be that although PrintStream.write(byte buf[], int off, int len) is synchronized, I can see in ch.qos.logback.core.joran.spi.ConsoleTarget that System.out.write(int b) is the only write method called.

So in between logback outputting each byte, the thirdparty library is managing to write a whole string to the stdout.

Patch provided: http://gist.github.com/434516

Please apply to an up coming release.

I have tested the patch in my application and can confirm that the interleaving of lines is fixed and no other side effects were observed.


This message is automatically generated by JIRA.
If you think it was sent incorrectly contact one of the administrators: http://jira.qos.ch/secure/Administrators.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira


More information about the logback-dev mailing list