[ 
https://issues.apache.org/jira/browse/LOG4J2-3440?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17512467#comment-17512467
 ] 

Pablo Rogina edited comment on LOG4J2-3440 at 3/25/22, 4:31 PM:
----------------------------------------------------------------

[~pkarwasz] > Returning all the appenders used by the associated Log4j2 logger 
seems excessive

Should those be the only appenders within the whole framework?

[~ggregory] >the whole "aai" implementation feels wrong since this is now a 
bridge rather than an implementation

Yes, I agree. The bridge should be like an interpreter between what's already 
coded for 1.2.x API and the underlying 2.x API + implementation

So not to influence your final work, this is what I've done just as interim 
solution for my issue (given the time constraints and deadlines to meet), so to 
get the appenders of the root logger:

[pseudo-code]

{{if LOG4J_CORE_PRESENT }}{{{}}

{{     root = org.log4j.logging.LogManager.getRootLogger()}}

{{     ctx = root.getContext()     }}

{{    config = ctx.getConfiguration()}}

{{     rootConfig = config.getRootLogger()}}

{{     appenders = rootConfig.getAppenders()}}

{{ }}}

I've tested with something like rootLogger=INFO (not specifying any appender) 
and in such case rootConfig.getAppenders() returns an empty array (which is 
expected for me).


was (Author: JIRAUSER286891):
[~pkarwasz] > Returning all the appenders used by the associated Log4j2 logger 
seems excessive

Should those be the only appenders within the whole framework?

[~ggregory] >the whole "aai" implementation feels wrong since this is now a 
bridge rather than an implementation

Yes, I agree. The bridge should be like an interpreter between what's already 
coded for 1.2.x API and the underlying 2.x API + implementation

So not to influence your final work, this is what I've done just as interim 
solution for my issue (given the time constraints and deadlines to meet), so to 
get the appenders of the root logger:

[pseudo-code]

if LOG4J_CORE_PRESENT {

    root = org.log4j.logging.LogManager.getRootLogger()

    ctx = root.getContext()

    config = ctx.getConfiguration()

    rootConfig = config.getRootLogger()

    appenders = rootConfig.getAppenders()
}

I've tested with something like rootLogger=INFO (not specifying any appender) 
and in such case rootConfig.getAppenders() returns an empty array (which is 
expected for me). 

> Log4j 1.2 bridge getAllAppenders() returns null enumeration
> -----------------------------------------------------------
>
>                 Key: LOG4J2-3440
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-3440
>             Project: Log4j 2
>          Issue Type: Bug
>          Components: Log4j 1.2 bridge
>    Affects Versions: 2.17.2
>            Reporter: Pablo Rogina
>            Assignee: Piotr Karwasz
>            Priority: Major
>             Fix For: 2.17.3
>
>
> Old application using Log4j 1.2.x relies on Logger.getAllAppenders() to 
> decide if Log4j it's already configured (returned Enumeration has at least 1 
> appender) or not (empty returned Enumeration).
> Some recent code audits mandate to remove log4j v1 component(s) and to 
> upgrade to latest 2.17.2 release, so we're using Log4j 1.2 Bridge to comply 
> and not to change application code.
> However, we're facing the issue describe here [1] for 
> Logger.getRootLogger().getAllAppenders() although with latest Log4j release 
> 2.17.2 the issue seems to be that data structure aai is never updated with 
> the proper configured appenders, given that now most of the work happens in 
> the Log4j v2 Core implementation, thus using LoggerContext
> [1] [java - Log4j getAllAppenders() returns null enumeration - Stack 
> Overflow|https://stackoverflow.com/questions/32864929/log4j-getallappenders-returns-null-enumeration]
>  
>  



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

Reply via email to