logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alexander Spitzer <aspit...@gmail.com>
Subject Re: How can I write a custom appender to supports Throwable as a second parameter?
Date Mon, 28 Sep 2009 15:56:06 GMT
I think I just did not explain it well (though there is a good chance
I am doing something wrong too.)

I followed an example on the web on how to create a custom appender.
It is essentially:

public class MyAppender extends AppenderSkeleton
private void init_vars(){
}
protected void append(LoggingEvent event) {
//do all my work here with the logged event.
 System.out.println("MyAppender Test:" + forcedLayout.format(event));
}


I configure log4j.properties to load it, and it works fine if the
developers only use:
logger.error("this is an error")

but if they use
logger.error("this is an error",myException)

then it fails. It does not appear that there is an overloadable method
for append(LogEvent,Throwable) in the AppenderSkeleton class, so I am
not sure how I am supposed to catch this OTHER signature for
logger.error(LoggingEvent,Throwable)

Should I also be overloading some Logger methods too?

Does that make more sense? Am I still way off on what I was looking to
do? Is this just as confusing, but in a different form :)

Thanks!

-alex spitzer

Cell: 617.407.2274
AIM: AlexSpitzer




On Mon, Sep 28, 2009 at 11:29 AM, Michael Erskine
<michael.erskine@ketech.com> wrote:
>> From: Alexander Spitzer [mailto:aspitzer@gmail.com]
>> Subject: How can I write a custom appender to supports Throwable as a second
>> parameter?
>>
>> Is it possible to write a custom appender that can take an exception
>> as a second parameter?
>>
>> I wrote a custom appender per the instructions on the log4j site which
>> extends AppenderSkeleton.
>>
>> Later, I found out that some of the developers use logger.xxx(String,
>> Throwable) instead of just the vanilla logger.xxx(String) call.
>> Looking through AppenderSkeleton, it does not appear to have an
>> overridable method for "Throwable" as the second parameter, and so my
>> method for:
>>
>> protected void append(LoggingEvent event, Throwable exin)
>>
>> just gets ignored.
>
> Alex,
> You're confusing Appender methods with Logger methods!
>
> Regards,
> Michael Erskine.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Mime
View raw message