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

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

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: logback-core
    • Labels:
      None
    • Environment:

      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

        Activity

        Hide
        diroussel David Roussel added a comment -

        This change has been included in logback 0.9.22.

        Show
        diroussel David Roussel added a comment - This change has been included in logback 0.9.22.
        Hide
        diroussel David Roussel added a comment -

        This ticket can be closed.

        Show
        diroussel David Roussel added a comment - This ticket can be closed.
        Hide
        noreply.ceki@qos.ch Ceki Gulcu added a comment -

        closed per reporter's wishes.

        Show
        noreply.ceki@qos.ch Ceki Gulcu added a comment - closed per reporter's wishes.

          People

          • Assignee:
            logback-dev@qos.ch Logback dev list
            Reporter:
            diroussel David Roussel
          • Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: