[log4perl-devel] log4perl appenders with warp_message=0 (fwd)
(forwarded with permission) Hi Mike. I've been enjoying Log::Log4perl (using 1.13). Thank-you. Until I decided to write a pair of appenders. One of them is a fancy file appender and it works nicely. 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? Thomas Erskine Consultant | Technology 2000 Barrington St | Suite 300 | Floor 04 Halifax, NS B3J3K1 Phone: +1 902 442-4709 [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/vse012070mrt/direct/01/ ___ log4perl-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/log4perl-devel
Re: [log4perl-devel] log4perl appenders with warp_message=0 (fwd)
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/PatternLayout.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]
-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
log4perl-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/log4perl-devel
Re: [log4perl-devel] 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.
>
-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
log4perl-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/log4perl-devel
Re: [log4perl-devel] setting defaults for appenders
On Mon, May 12, 2008 at 02:21:23PM -0700, Jonathan Swartz wrote: > I've got a growing number of log files for different categories that I > would like to all have the same layout and pattern, e.g. You can use "Variable Substitution" as described in the man page, but that still seems awkward. -- Bill Moseley [EMAIL PROTECTED] - This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/ ___ log4perl-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/log4perl-devel
Re: [log4perl-devel] log4perl appenders with warp_message=0
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: [email protected]
> 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
> > > > layo
[log4perl-devel] Understanding the config
I inherited an existing Log4perl configuration, and I think I'm missing some key point. The config file starts out: log4perl.rootLogger = INFO, syslogAppender, screenAppender >From the examples I've seen and the ::Config docs I thought it should be "log4perl.logger" not "log4perl.rootLogger". Yet, logging is working as expected. So, I'm curious about the difference. In ::Config it also give these examples: log4perl.logger.Bar.Twix = DEBUG, A1 log4perl.category.Bar.Twix = WARN, Screen Why is it "category" instead of "logger"? Finally, for a config like this in the example, what would be the perl code equivalent if not using a config file? log4perl.logger.Bar.Twix = DEBUG, A1 log4perl.appender.A1=Log::Log4perl::Appender::File log4perl.appender.A1.filename=test.log log4perl.appender.A1.mode=append log4perl.appender.A1.layout = \ Log::Log4perl::Layout::PatternLayout log4perl.appender.A1.layout.ConversionPattern = %d %m %n Like this? use Log::Log4perl qw(:levels); use Log::Log4perl::Appender::File; my $appender = Log::Log4perl::Appender::File->new( filename => 'test.log', mode => 'append', layout=> Log::Log4perl::Layout::PatternLayout->new( '%d %m %n'), ); my $logger = Log::Log4perl->get_logger( 'Bar::Twix' ); $logger->level( $DEBUG ); $logger->add_appender( $appender ); -- Bill Moseley [EMAIL PROTECTED] - This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/ ___ log4perl-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/log4perl-devel
Re: [log4perl-devel] setting defaults for appenders
On Mon, May 12, 2008 at 02:21:23PM -0700, Jonathan Swartz wrote: > I've got a growing number of log files for different categories that I > would like to all have the same layout and pattern, e.g. You can use "Variable Substitution" as described in the man page, but that still seems awkward. -- Bill Moseley [EMAIL PROTECTED] - This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/ ___ log4perl-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/log4perl-devel
Re: [log4perl-devel] setting defaults for appenders
> On Fri, 9 May 2008, Jonathan Swartz wrote: > >> I've got a growing number of log files for different categories >> that I >> would like to all have the same layout and pattern, e.g. > > Hi Jonathan, > > this is one of the items on my todo-list: To have an inheritance > mechanism that lets you say something like > >log4perl.appender.file.inherits_from = \ >log4perl.appender.file_base > > and any property you don't specify in 'file' is inherited from > file_base. It's not in L4p yet, but hopefully soon! ;) > That would be great! In the meantime, I might try to do this myself by creating my own Appender subclass: # My::Log4perl::Appender::File defaults to my preferred layout and layout.ConversionPattern log4perl.appender.file1 = My::Log4perl::Appender::File log4perl.appender.file2 = My::Log4perl::Appender::File Do you have a vague idea of how I might approach this? Or is it too diffiicult, and I should just suck up the repetition until the inheritance feature? :) Jon - This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/ ___ log4perl-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/log4perl-devel
