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

Using log4j-1_2-api to load XML configuration - Logger.getAppenders() empty

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 2.19.0
    • None
    • Log4j 1.2 bridge
    • None

    Description

      I have used the log4j 1.2 bridge XmlConfigurator to load a 1.2 XML configuration and performed a `Configurator.reconfigure(configuration)`.

      Then I retrieved a logger using "Logger.getLogger(String)".

      When I then call 'Logger.getAppenders()" the returned enumeration is empty.

      Looking at the logger in the debugger I can see the attached Appenders in the associated LoggerConfig.

      In `org.apache.log4j.Category` I stepped through and got to here which returned an empty collection.

      I might be doing something wrong ... it has been known to happen.   But I was expecting to get the two configured appenders "console" and "file" here.

      The "problem" seems to be here with the stream filter:

      return Collections.enumeration(appenders.stream()
                          // omit native Log4j 2.x appenders
                          .filter(AppenderAdapter.Adapter.class::isInstance)
                          .map(AppenderWrapper::adapt)
                          .collect(Collectors.toSet()));

      The Javadoc in `Category` does say:

       Get all the Log4j 1.x appenders contained in this category as an {@link Enumeration}. Log4j 2.x appenders are omitted.

      But I did load the configuration with the Bridge and I was hoping my legacy code would still get the Appenders as before.

      Attachments

        1. image-2022-11-13-02-02-03-595.png
          51 kB
          Jeff Thomas
        2. image-2022-11-13-02-05-42-235.png
          27 kB
          Jeff Thomas

        Activity

          People

            pkarwasz Piotr Karwasz
            JWT007 Jeff Thomas
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated: