Log4j 2
  1. Log4j 2
  2. LOG4J2-189

AsynchAppender: "blocking" parameter doesn't work

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.0-beta4
    • Fix Version/s: 2.0-beta5
    • Component/s: Appenders
    • Labels:
      None

      Description

      AsynchAppender parameter:
      blocking=false ==> LogEvents are never distributed to other appenders
      blocking=true ==> the appender don't blocks if the queue is full

      proposal for solution:

      AsynchAppender.java
      public void append(final LogEvent event) {
      if (!isStarted())

      { throw new IllegalStateException("AsynchAppender " + getName() + " is not active"); }

      if (event instanceof Log4jLogEvent) {

      // if (blocking && queue.remainingCapacity() > 0) {
      // try

      { // queue.add(Log4jLogEvent.serialize((Log4jLogEvent) event)); // return; // }

      catch (final IllegalStateException ex)

      { // error("Appender " + getName() + " is unable to write primary appenders. queue is full"); // }
      // }
      // if (errorAppender != null) {
      // if (!blocking) { // error("Appender " + getName() + " is unable to write primary appenders. queue is full"); // }

      // errorAppender.callAppender(event);
      // }
      boolean appendSuccessful = false;
      if (blocking){
      try

      { queue.put(Log4jLogEvent.serialize((Log4jLogEvent) event)); // wait for free slots in the queue appendSuccessful = true; }

      catch (InterruptedException e) {
      LOGGER.warn("Interrupted while waiting for a free slots in the LogEvent-queue at the AsynchAppender {}", getName());
      }
      }else{
      appendSuccessful = queue.offer(Log4jLogEvent.serialize((Log4jLogEvent) event));
      if (!appendSuccessful)

      { error("Appender " + getName() + " is unable to write primary appenders. queue is full"); }

      }
      if ((!appendSuccessful) && (errorAppender != null))

      { errorAppender.callAppender(event); }

      }
      }

        Activity

          People

          • Assignee:
            Ralph Goers
            Reporter:
            Werner
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development