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

Wrong value "false" of RollingFileAppender.immediateFlush when configured from a Log4j 1.x configuration

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 2.14.1
    • 2.15.0
    • Appenders
    • None

    Description

      Unlike the simple FileAppender (both from a Log4j 1.x and 2.x configuration) and the RollingFileAppender configured from a 2.x configuration, the property "immediateFlush" has the value "false" on RollingFileAppender configured from a Log4j 1.x configuration. This leads to apparently not logging into the file (the automatic flush occurs only after a high amount of data and respectively a long time).

      The code reveals two relevant differences:

      • "immediateFlush" has the fixed default-value "false" in the 1.x configuration-flow (see for eg.
        org.apache.log4j.builders.appender.RollingFileAppenderBuilder.parseAppender()

        , the same as in

        org.apache.log4j.builders.appender.FileAppenderBuilder.parseAppender()

        ), unlike in the 2.x configuration-flow (

        org.apache.log4j.core.appender.AbstractOutputStreamAppender.Builder.immediateFlush

        has the default-value "true")

      • the value of "immediateFlush" is taken from
        !bufferedIo || isImmediateFlush()

        for a FileAppender, which is missing from the RollingFileAppender

       

      To reproduce, build and start the attached demo-application (initializes Log4j2 from a Log4j 1.x configuration and prints periodically a log-entry to the console, to a FileAppender and to a RollingFileAppender). Execute "tail -f" on the file of the simple appender (log.log) and on that of the rolling appender (rlog.log) and observe, that logging output doesn't appear on the latter, until the application is stopped.

      Attachments

        1. rolling-file-not-flushed.tgz
          1 kB
          Barnabas Bodnar

        Issue Links

          Activity

            People

              rgoers Ralph Goers
              bbodnar Barnabas Bodnar
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: