[
https://issues.apache.org/jira/browse/LOG4J2-3632?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17633295#comment-17633295
]
Jeff Thomas commented on LOG4J2-3632:
-------------------------------------
Hallo [~rgoers] , thanks for the quick answer.
Yeah I sort of figued that by the time I got to the end of writing this ticket.
:)
What still confuses me a bit...
If I look at the bridge builders (ie. RollingFileAppenderBuilder) they create
AdapterWrappers, but in XmlConfiguration these are then adapted back to Log4j2
Appenders. So as you said all Log4j 1.2 Appenders are then stored as Log4j 2.x
Appenders.
So what exactly does this method return? Or rather, when would the Log4j1
Adapter actually return a Log4j1 Adapter representation? Only programmatically
added Appenders? Or only special cases like the ListAppender?
I am guessing when migrating our application to log4j 2 that we can no longer
use this method to reliably get a list of Log4j 1.2 Appender "wrappers" to
Log4j 2.x Appenders and need to change all code over to use the Log4j 2 APIs?
> Using log4j-1_2-api to load XML configuration - Logger.getAppenders() empty
> ---------------------------------------------------------------------------
>
> Key: LOG4J2-3632
> URL: https://issues.apache.org/jira/browse/LOG4J2-3632
> Project: Log4j 2
> Issue Type: Bug
> Components: Log4j 1.2 bridge
> Affects Versions: 2.19.0
> Reporter: Jeff Thomas
> Priority: Major
> Attachments: image-2022-11-13-02-02-03-595.png,
> image-2022-11-13-02-05-42-235.png
>
>
> 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.
> !image-2022-11-13-02-02-03-595.png!
> In `org.apache.log4j.Category` I stepped through and got to here which
> returned an empty collection.
> !image-2022-11-13-02-05-42-235.png!
> 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:
> {code:java}
> return Collections.enumeration(appenders.stream()
> // omit native Log4j 2.x appenders
> .filter(AppenderAdapter.Adapter.class::isInstance)
> .map(AppenderWrapper::adapt)
> .collect(Collectors.toSet()));{code}
> The Javadoc in `Category` does say:
> {quote} Get all the Log4j 1.x appenders contained in this category as an
> \{@link Enumeration}. Log4j 2.x appenders are omitted.
> {quote}
> But I did load the configuration with the Bridge and I was hoping my legacy
> code would still get the Appenders as before.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)