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

Log4j 1.x bridge Logger.getAppender returns a wrapped AppenderAdapter

    XMLWordPrintableJSON

Details

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

    Description

      In our code, we have a custom logger and a custom multiprocess rolling FileAppender as below shown in below code snippet.

       

      For some processing, we need to get appender from logger, so we call Logger.getAppender() but with log4j1.x bridge it is returning AppenderWrapper unlike log4j1.x where we used to get an Appender.

       

      We need to typecast returned value to FileAppender but since now it AppenderWrapper, so it is throwing exception "java.lang.ClassCastException: org.apache.log4j.bridge.AppenderWrapper cannot be cast to org.apache.log4j.FileAppender".

      To fix cast exception we are overriding getAppender in our customLogger as shown below, however we are still having some minor issues in reading property value but may be this new issue is due to some other problems. I am still trying to figure out.

      I am creating this Jira ticket with a hope that if there is a possibility then may be log4j1.x bridge can be modified to provide this conversion instead we override this method in our custom logger.

      @Override    public Appender getAppender(final String name) {        AppenderWrapper appenderWrapper = (AppenderWrapper) super.getAppender(name);        return ((AppenderAdapter.Adapter)appenderWrapper.getAppender()).getAppender();    }

       

      public class CustomLogger extends Logger implements java.io.Serializable {}

       

      public class CustomMultiProcessRollingAppender extends FileAppender { }

      Attachments

        Issue Links

          Activity

            People

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

              Dates

                Created:
                Updated:
                Resolved: