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

ASF subversion and git services commented on LOG4J2-3426:
---------------------------------------------------------

Commit ba16485b93cde4f05e0cbb2ca564a7b6cb6d4d77 in logging-log4j2's branch 
refs/heads/dependabot/maven/slf4jVersion-1.7.36 from Piotr P. Karwasz
[ https://gitbox.apache.org/repos/asf?p=logging-log4j2.git;h=ba16485 ]

[LOG4J2-3426] Refactors wrapping code

Refactors the wrapping logic into single `wrap` or `adapt` methods to be
sure we always perform the correct logic.


> Log4j 1.x bridge Logger.getAppender returns a wrapped AppenderAdapter
> ---------------------------------------------------------------------
>
>                 Key: LOG4J2-3426
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-3426
>             Project: Log4j 2
>          Issue Type: Bug
>          Components: Log4j 1.2 bridge
>    Affects Versions: 2.17.2
>            Reporter: Pooja Pandey
>            Assignee: Piotr Karwasz
>            Priority: Major
>             Fix For: 2.17.3
>
>
> 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 \{ }



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

Reply via email to