Uploaded image for project: 'logback'
  1. logback
  2. LOGBACK-78

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

    XMLWordPrintable

Details

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Major Major
    • None
    • None
    • logback-core
    • None
    • java 1.6.0 on Windows XP

    Description

      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.

      David

      Attachments

        Activity

          People

            logback-dev Logback dev list
            diroussel David Roussel
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: