Skip Menu |

This queue is for tickets about the Log-Log4perl CPAN distribution.

Report information
The Basics
Id: 78627
Status: open
Priority: 0/
Queue: Log-Log4perl

People
Owner: Nobody in particular
Requestors: NHORNE [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: 1.37
Fixed in: (no value)



Subject: Different actions for different levels
It would be great if I could specify in the log file that different things happen for different levels, e.g. warns and above get sent to a file, fatal gets sent to an email (as well as into the file) e.g.: log4perl.logger.bb-links.pl=(WARN, A1) (FATAL, A2) log4perl.appender.A1=Log::Dispatch::File ... log4perl.appender.A2=Log::Dispatch::Email ...
Sending messages of different log levels to separate appenders is well supported in Log4perl. Just define a logger for the lower level, forward its messages to both appenders, and use Log4perl's filters to route them to the correct appender later, like in this example for two different log files: http://search.cpan.org/dist/Log- Log4perl/lib/Log/Log4perl/FAQ.pm#I_want_to_log_ERROR_and_WARN_messages_to _different_files!_How_can_I_do_that?
On Sat Jul 28 13:26:24 2012, MSCHILLI wrote: Show quoted text
> Sending messages of different log levels to separate appenders is well > supported in Log4perl. Just define a logger for the lower level, forward > its messages to both appenders, and use Log4perl's filters to route them > to the correct appender later, like in this example for two different log > files:
Thanks for your reply. I think, however, you missed the all important "and above" in my original post. Your FAQ item does not do what I asked for.
On Sun Jul 29 10:28:58 2012, NHORNE wrote: Show quoted text
> Thanks for your reply. I think, however, you missed the all important > "and above" in my original post. Your FAQ item does not do what I > asked for.
Well, it doesn't say so explicitly, but to specify a range instead of a match, you can simply use LevelRange instead of LevelMatch. So, instead of log4perl.filter.MatchError = Log::Log4perl::Filter::LevelMatch log4perl.filter.MatchError.LevelToMatch = ERROR as outlined in the FAQ to match 'ERROR', if you want 'ERROR and above', use log4perl.filter.MatchError = Log::Log4perl::Filter::LevelRange log4perl.filter.MatchError.LevelMin = ERROR Let me know if this makes sense.
Subject: Re: [rt.cpan.org #78627] Different actions for different levels
Date: Wed, 01 Aug 2012 10:51:27 +0100
To: bug-Log-Log4perl [...] rt.cpan.org
From: Nigel Horne <njh [...] bandsman.co.uk>
Michael, Thank you for your reply. I tried that, but now nothing gets logged at all. I must have broken and/or misunderstood something. Here's a conf file: log4perl.logger.cb-links.pl=DEBUG, A1, A2 log4perl.appender.A1=Log::Dispatch::File log4perl.appender.A1.Filter=MatchDebug log4perl.appender.A1.filename=/tmp/cb-links.log log4perl.appender.A1.mode=append log4perl.appender.A1.layout=Log::Log4perl::Layout::PatternLayout log4perl.appender.A1.layout.ConversionPattern=%d %p> %F{1}:%L %M - %m%n log4perl.appender.A2=Log::Dispatch::Email::MailSendmail log4perl.appender.A2.Filter=MatchError log4perl.appender.A2.to='njh@bandsman.co.uk' log4perl.appender.A2.subject='Error in cb-links' log4perl.appender.A2.layout=Log::Log4perl::Layout::PatternLayout log4perl.appender.A2.layout.ConversionPattern=%d %p> %F{1}:%L %M - %m%n log4perl.filter.MatchDebug=Log::Log4perl::Filter::LevelMatch log4perl.filter.MatchDebug.LevelMin=DEBUG log4perl.filter.MatchError=Log::Log4perl::Filter::LevelMatch log4perl.filter.MatchError.LevelMin=ERROR And here's the code which calls it: Log::Log4perl->init($info->script_dir . "/../conf/$script_name.l4pconf"); my $logger = Log::Log4perl->get_logger($script_name); ... $logger->debug('testing debug'); $logger->error('testing error); Regards, -Nigel
Almost there. You just need to change Log::Log4perl::Filter::LevelMatch to Log::Log4perl::Filter::LevelRange as outlined earlier.
On Wed Aug 01 12:22:05 2012, MSCHILLI wrote: Show quoted text
> as outlined earlier.
Sorry, my bad, just realized that I goofed this up in my earlier post ;).
Subject: Re: [rt.cpan.org #78627] Different actions for different levels
Date: Thu, 02 Aug 2012 10:29:21 +0100
To: bug-Log-Log4perl [...] rt.cpan.org
From: Nigel Horne <njh [...] bandsman.co.uk>
On 01/08/12 17:24, Michael_Schilli via RT wrote: Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=78627> > > On Wed Aug 01 12:22:05 2012, MSCHILLI wrote:
>> as outlined earlier.
> Sorry, my bad, just realized that I goofed this up in my earlier post ;). >
Yes, that now works - thanks so much. Do you not think it would be helpful for Log::Log4perl to have generated an error in the init() method when I used LevelMatch in conjunction with LevelMin, instead of LevelRange? -Nigel -- Arranger, Adjudicator, Band Trainer and Clinician, Composer, Tutor, Typesetter. NJH Music, ICQ#20252325, twitter: @nigelhorne njh@bandsman.co.uk http://www.bandsman.co.uk
On Thu Aug 02 05:29:39 2012, njh@bandsman.co.uk wrote: Show quoted text
> Do you not think it would be helpful for Log::Log4perl to have
generated Show quoted text
> an error in the init() > method when I used LevelMatch in conjunction with LevelMin, instead of > LevelRange?
Yes, absolutely, let me put that on my (long) todo list! :).