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

Provide an appender similar to log4js AsyncAppender

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.0.4
    • Component/s: logback-classic
    • Labels:
      None

      Description

      We're using log4j successfully in financial B2B / B2C web applications for years. Now we would like to adopt Logback but therefore we need support for an asynchronous appender decorator like log4js AsyncAppender.

      Attached you can find my take on this kind of appender cobbled together from ideas and code from various places:

      1. 0001-Addition-of-AsyncAppender-class-and-tests.patch
        31 kB
        Gordon Sims
      2. AsyncAppender_logback-test.xml
        0.6 kB
        Torsten Juergeleit
      3. AsyncAppender.java
        12 kB
        Torsten Juergeleit
      4. AsyncAppenderInitializationTest.java
        2 kB
        Torsten Juergeleit
      5. AsyncAppenderTest.java
        11 kB
        Torsten Juergeleit

        Issue Links

          Activity

          Hide
          yairogen yair ogen added a comment -

          Is this appender going to be officially included in logback classic any time soon?

          Show
          yairogen yair ogen added a comment - Is this appender going to be officially included in logback classic any time soon?
          Hide
          borislav.andruschuk Borislav Andruschuk added a comment -

          I've reviewed patch and found the piece of code that's not thread safe. Look at exceptionRepeatCount variable in appender, It can be modified from several threads without exclusive access in append method - you got race condition in this place. Variable should be just converted from class field to method local variable.

          Show
          borislav.andruschuk Borislav Andruschuk added a comment - I've reviewed patch and found the piece of code that's not thread safe. Look at exceptionRepeatCount variable in appender, It can be modified from several threads without exclusive access in append method - you got race condition in this place. Variable should be just converted from class field to method local variable.
          Hide
          noreply.ceki@qos.ch Ceki Gulcu added a comment -

          LBCLASSIC-242 is the (arbitrarily chosen) umbrella issue for the addition of AsyncAppender in logback

          Show
          noreply.ceki@qos.ch Ceki Gulcu added a comment - LBCLASSIC-242 is the (arbitrarily chosen) umbrella issue for the addition of AsyncAppender in logback
          Hide
          noreply.ceki@qos.ch Ceki Gulcu added a comment -

          Fixed in https://github.com/qos-ch/logback/commit/f495e50ba6

          Please review. From the docs: AsyncAppender buffers events in a BlockingQueue. A worker thread created by AsyncAppender takes events from the head of the queue, and dispatches them to the single appender attached to AsyncAppender. Note that by default, AsyncAppender will drop events of level TRACE, DEBUG and INFO if its queue is 80% full. This strategy has an amazingly favorable effect on performance at the cost of event loss. Event loss can be prevented by setting the discardingThreshold property to 0 (zero).

          Show
          noreply.ceki@qos.ch Ceki Gulcu added a comment - Fixed in https://github.com/qos-ch/logback/commit/f495e50ba6 Please review. From the docs: AsyncAppender buffers events in a BlockingQueue. A worker thread created by AsyncAppender takes events from the head of the queue, and dispatches them to the single appender attached to AsyncAppender. Note that by default, AsyncAppender will drop events of level TRACE, DEBUG and INFO if its queue is 80% full. This strategy has an amazingly favorable effect on performance at the cost of event loss. Event loss can be prevented by setting the discardingThreshold property to 0 (zero).
          Hide
          ceefour Hendy Irawan added a comment -

          Thank you Torsten !

          Show
          ceefour Hendy Irawan added a comment - Thank you Torsten !

            People

            • Assignee:
              noreply.ceki@qos.ch Ceki Gulcu
              Reporter:
              tjuerge Torsten Juergeleit
            • Votes:
              16 Vote for this issue
              Watchers:
              18 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: