Re: java.lang.ClassCastException: org.apache.log4j.bridge.AppenderWrapper cannot be cast to org.apache.log4j.FileAppender

Pooja Pandey <[email protected]>
Newsgroups gmane.comp.jakarta.log4j.user
Message-ID <MW4PR02MB7220F30FA0CFCB1B5493A3CF92069@MW4PR02MB7220.namprd02.prod.outlook.com>
Thank you so much Piotr for detailed explanation of bug. I will create JIRA ticket ASAP and shortly will reply with details also you have asked.

Get Outlook for iOS<https://aka.ms/o0ukef>
________________________________
From: Piotr P. Karwasz <[email protected]>
Sent: Saturday, March 5, 2022 7:23:34 PM
To: Log4J Users List <[email protected]>
Subject: Re: java.lang.ClassCastException: org.apache.log4j.bridge.AppenderWrapper cannot be cast to org.apache.log4j.FileAppender

*** External email: Verify sender before opening attachments or links ***


Hi Pooja,

On Sat, Mar 5, 2022 at 1:48 PM Pooja Pandey
<[email protected]> wrote:
> Hi Piotr,
>
> I don’t understand what is the bug?? Can you please help me with JIRA
> ticket summary and description.

The bug is that if you use a native Log4j 1.2 appender (a derivative
class of org.apache.log4j.FileAppender for example) a call to
`Logger.getAppender(String)` gives you an AppenderWrapper of an
AppenderAdapter instead of the original class. Such useless
encapsulations should not be present, but apparently we missed some.
Summarizing "Log4j 1.x bridge Logger.getAppender returns a wrapped
AppenderAdapter"
In the Jira ticket just describe your exact situation: are you using a
configuration file or are you adding the appenders in code? Are you
always using a LoggerFactory?
My wild guess is that you configure a subclass of
org.apache.log4j.FileAppender (let's call it com.example.FileAppender)
in a configuration file. In your code you call `Logger.getAppender()`
and you get an AppenderWrapper instead of com.example.FileAppender. If
the guess is true, it is an easy fix.

Piotr

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.