On Tue, 13 May 2008, Erskine, Thomas (IT) wrote:

> I do indeed want
>
>       $logger->log($level, $msg, $key)
>
> to be dealt with differently depending on the appender it ends up on.
> That's part of the point of having different appenders; they ought to be
> independant.  The problem is that it doesn't seem possible to use
> appenders simultaneously which set (and require) warp_message=0 and ones
> which don't.

I don't think that this is true, warp_message is a per-appender setting
and can be set individually (and differently) per appender. The
restriction is that the you need to use the NoopLayout with the appender
that has warp_message set.

> I've just thought of another way to do this.  If I set
> warp_message=sub{return $_[0]} on the file appender, then things
> should just work.  I don't like putting code in the log configuration
> file, but it's worth a shot.  Just a sec...  Yup.  It works.

That's exactly right -- and since it's per-appender, it won't affect the
other 'fancy' appender. But, the ugly part is that with warp_message
turned on, the appender's log() method gets an a reference to an array
of message chunks, which the file appender can't deal with.

> The problem with using the MDC is that this isn't something which is
> intended to persist for a while.  The whole point is to be able to set
> the Netcool AlertKey on a per-message basis.  Of course I _could_ use
> the MDC, but my usage would look like:
>
>   Log::Log4perl::MDC->put("netcool-key", $key);
>   $logger->log($level, $msg);
>   Log::Log4perl::MDC->put("netcool-key", undef);
>
> which isn't exactly handy.

... or you define a wrapper around that:

    http://log4perl.sourceforge.net/d/Log/Log4perl.html#6acb7

-- Mike

Mike Schilli
[EMAIL PROTECTED]


>
> > -----Original Message-----
> > From: Mike Schilli [mailto:[EMAIL PROTECTED]
> > Sent: Tuesday, May 13, 2008 2:26 AM
> > To: Erskine, Thomas (IT)
> > Cc: [EMAIL PROTECTED]
> > Subject: Re: log4perl appenders with warp_message=0
> >
> > On Fri, 9 May 2008, Erskine, Thomas (IT) wrote:
> >
> > > The other logs an event to Netcool (specifying
> > warp_message=0) and it
> > > works fine.  It allows you to call log like:
> > >
> > >     $logger->log($level, $msg, $key)
> > >
> > > so that you can specify a Netcool alert key.
> > >
> > > Then comes the problem: I made a configuration file including both
> > > appenders.  Now I lose.  The Netcool appender continues to
> > work nicely.
> > > However, the file appender mashes all the args together if
> > I specify
> > > the key.  Which is the expected behaviour for it, but then
> > I can't use
> > > the key feature with netcool.  I could make it work by setting
> > > warp_message=0 on the file appender, but to do that I have
> > to set the
> > > layout to NoopLayout, so I can't get nicely formatted log
> > entries there.
> > >
> > > It seems as if there is no way to use both types of appender (with
> > > warp_message=0 and without) in the same config file.  Or am
> > I missing
> > > something?
> >
> > Hi Thomas,
> >
> > It seems like you want a statement like
> >
> >     $logger->log($level, $msg, $key)
> >
> > to have two different meanings, depending on which appender
> > the message ends up at.
> >
> > On the Netcool appender, you want it to use the $key for a
> > special purpose, on the file appender, you want it to sweep
> > $key under the carpet -- seems inconsistent to me, as it's
> > not clear what another random new appender would do with this.
> >
> > For cases like this, I would stuff the Netcool key in the MDC:
> >
> >     http://log4perl.sourceforge.net/d/Log/Log4perl/MDC.html
> >
> > So instead of saying
> >
> >     $logger->log($level, $msg, $key);
> >
> > you would say
> >
> >     Log::Log4perl::MDC->put("netcool-key", $key);
> >     $logger->log($level, $msg);
> >
> > and the Netcool appender would either fetch the the key from
> > the MDC in its log() method and do something with it or you
> > could access it as %X{netcool-key} in the layout:
> >
> >
> > http://log4perl.sourceforge.net/d/Log/Log4perl/Layout/PatternL
> > ayout.html
> >
> > Would that work for you?
> >
> > Can I post this message to the mailing list? Looks like this
> > could be useful for other folks as well.
> >
> > -- Mike
> >
> > Mike Schilli
> > [EMAIL PROTECTED]
> >
> --------------------------------------------------------
>
> NOTICE: If received in error, please destroy and notify sender. Sender does 
> not intend to waive confidentiality or privilege. Use of this email is 
> prohibited when received in error.
>

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft 
Defy all challenges. Microsoft(R) Visual Studio 2008. 
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
log4perl-devel mailing list
log4perl-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/log4perl-devel

Reply via email to