Uploaded image for project: 'Log4j 2'
  1. Log4j 2
  2. LOG4J2-1197

Improve RollingFileAppender to avoid having stale log events in the buffer

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Open
    • Major
    • Resolution: Unresolved
    • None
    • None
    • None

    Description

      With bufferedIO=true the buffer contains log events that I want to see, but the buffer is only flushed to disk when it is full (which is not frequent enough).

      Typical scenario is when the server is not in production, so almost no traffic except for the request manually triggered by the operator, usually in order to debug something.

      From Remko:

      AsyncAppender or Async Loggers use smart batching, where the buffer will be flushed when the queue is empty. This results in efficient IO (lumping together IO operations where possible), and at the same time your log file always reflects the most recent message.

      For synchronous buffered logging, a smarter flushing mechanism would be useful.

      Question is, what would trigger the check (whether the buffer needs to be flushed)?

      • Easiest is to check with each log event, but if no new event arrives you still end up with a stale buffer. Better than nothing, but not great.
      • An alternative is to check periodically from a background thread and flush if the buffer is non-empty. This probably gives the best results but is fairly complex to implement.

      Note 1: The FlumeAppender uses a maxDelayMillis to address this.
      Note 2: Could all synchronous appenders benefit from this improvement?

      Attachments

        Activity

          People

            Unassigned Unassigned
            benjamin.jaton Benjamin Jaton
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated: