Hi Mike.

While warp_message is indeed an appender setting, if you have two
appenders, one with warp_message=0 and one without, then you'll get the
mess I got: the one with will work fine and will have access to extra
args separately, but the one without will mash the args into a single
message.  

Perhaps I ought to have said that, while it's possible to have appenders
with warp_message=0 and those without in the same setup, it's not
_useful_ as the result will be a mess.

The hackery with warp_mesage=sub{return $_[0]} has to be applied to the
fancy appender to override its wish to mash all the args together, not
the special appender.  This is the part which just feels wrong.  I made
the Netcool appender, which I acknowledge is special and I don't mind
having to put special setup into it.  What seems wrong is having to
modify the setup for the other appender to make them both play nice.
I'd like to be able to keep the special handling all within the special
appender.  Just me being fussy.

On a completely different topic, while making a Null appender (which
discards everything), I noticed that it doesn't seem possible to make
the initializer shut up about it not having a layout.  Even though I
added in code to the new to cause it to inflict the NoopLayout to
itself.  It just seemed that I shouldn't have to provide configuration
for a Null appender, since it isn't doing anything.  Instead, I have to
say:

  log4perl.xxx.appender=Null
  log4perl.xxx.layout=NoopLayout
  log4perl.xxx.warp_message=0

I understand that you're just (properly) checking that people haven't
made a stupid mistake in forgetting the layout.

Thomas Erskine
Consultant | Technology
2000 Barrington St | Suite 300 | Floor 04
Halifax, NS B3J3K1
Phone: +1 902 442-4709
[EMAIL PROTECTED]
 

> -----Original Message-----
> From: Mike Schilli [mailto:[EMAIL PROTECTED] 
> Sent: Tuesday, May 13, 2008 12:43 PM
> To: Erskine, Thomas (IT)
> Cc: log4perl-devel@lists.sourceforge.net
> Subject: RE: log4perl appenders with warp_message=0
> 
> 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.
> >
>
--------------------------------------------------------

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