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

Log4j 1.x 2.17.2 bridge - Synchronization issue in multithreading (Losing huge data in multithreading)

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.17.2
    • 2.18.0
    • Log4j 1.2 bridge
    • None

    Description

      In our application we have migrated from log4j1.x to log4j1.x 2.17.2 bridge. With Log4j1.x there was no issue with multithreading but with log4j 1.x bridge we have noticed that in multithreading environment there is a huge data loss while logging, however single thread works fine. I see that in Category.java which Logger extends; many methods are not synchronized any more in log4j1.x bridge however which were synchronized in case of log4j1.x. I suspect this could be root causes of this multithreading problem.

      So as per my understanding synchronized class Category.java in the log4j1.x has become unsynchronized in log4j1.x 2.17.2 bridge. I am not sure if I am missing something.

      We wanted to know how to achieve successful multithreading logging using log4j 1.x 2.17.2 bridge.

      For reference, few methods which were synchronized earlier in log4j1.x but not anymore in log4j1.x bridge.

      1. public void addAppender(final Appender appender)
      2. public Appender getAppender(final String name)
      3. public void removeAppender(final Appender appender)
      4. public void removeAllAppenders()
      5. In log4j 1.x bridge following method is used for logging which doesn't look like synchronized. -> void maybeLog(final String fqcn, final org.apache.logging.log4j.Level level, final Object message, final Throwable throwable); However in log4j1.x following method was used which looks like synchronized. -> void forcedLog(String fqcn, Priority level, Object message, Throwable t) -> void callAppenders(LoggingEvent event), where method void callAppenders(LoggingEvent event) looks snychronized.

       

      I am attaching sample test program as well which I have used to test multithreading logging in my application. (Please Note that in this test program, class CustomLogger is a dummy class, which you would need to replace with your logger). We are using Custom Rolling Appender in our application and following is the content of log4j properties file. JavaLoggingMultiThTest.txt

      #Custom Rolling Appender
      log4j.appender.R=test.CustomMultiProcessRollingAppender
      log4j.appender.R.File=${user.home}/log4j-multithreading-test.log
      log4j.appender.R.RollOverOnStartup=true
      log4j.appender.R.RollOverOnSize=false
      log4j.appender.R.RollOverMaxFileSize=100MB
      log4j.appender.R.RollOverMaxBackupIndex=10
      log4j.appender.R.RollOverOnPeriodic=false
      log4j.appender.R.RollOverPeriodicStartDate=
      log4j.appender.R.RollOverPeriodicFrequency=1
      log4j.appender.R.layout=org.apache.log4j.PatternLayout
      log4j.appender.R.layout.ConversionPattern=%d %-8M [%t] - %m%n

      Attachments

        1. JavaLoggingMultiThTest.txt
          4 kB
          Pooja Pandey

        Activity

          People

            pkarwasz Piotr Karwasz
            PoojaTheCoder Pooja Pandey
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: