logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "James Stauffer" <stauffer.ja...@gmail.com>
Subject Re: Custom appender question about getRenderedMessage()
Date Fri, 23 Mar 2007 14:02:48 GMT
If you want to change the text of the message, you shouldn't do that
in the appender -- the layout is a much better place to do that.

Can you just change your ConversionPattern to the following and not
subclass RollingFileAppender?
<my custom text> %d %5p [%t][%40C::%-20M(%3L)]-%m%n

On 3/22/07, Bret Schuhmacher <bret@ingrian.com> wrote:
> Hi,
>
> I'm trying to extend RollingFileAppender.  I want to manipulate the
> *complete* message that's logged by prepending something to the message
> just before it's dumped into the file.
>
> My custom class's append() tries to create a new LoggingEvent from the
> given LoggingEvent, prepending my text to the
> event.getRenderedMessage(), then calls super.append(myNewLoggingEvent).
> Unfortunately,  getRenderedMessage just returns the original message I
> wanted logged, not the full message rendered with my ConversionPattern.
> My ConversionPattern is set to this, btw:
> %d %5p [%t][%40C::%-20M(%3L)]-%m%n
>
> Said another way, I want this:
> logger.debug("my message");
>
> to get rendered and written to file like this:
> <my custom text> 2007-03-22 19:05:05,615 DEBUG
> [main][com.xxxxxx.TestMain::<init> ( 26)]-my message
>
> Is there a way to make this happen?  I can't seem to get my hands on the
> full, rendered message ("2007-03-22 19:05:05,615 DEBUG
> [main][com.xxxxxx.TestMain::<init> ( 26)]-my message") so I can prepend
> "<my custom text>".
>
> I've tried creating an ObjectRenderer, too, but I don't think that's the
> way I should go (is it?).  If I could grab the full rendered message and
> prepend my String and then *reset* the rendered message I think I'd be
> fine, but I'm not sure...
>
> FWIW, I'm using 1.2.14.
>
>
> Thanks!
>
> Bret
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>
>


-- 
James Stauffer        http://www.geocities.com/stauffer_james/
Are you good? Take the test at http://www.livingwaters.com/good/

---------------------------------------------------------------------
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