eaiovnaovbqoebvqoeavibavo LevelRange.pm000064400000007051147635410140007136 0ustar00################################################## package Log::Log4perl::Filter::LevelRange; ################################################## use 5.006; use strict; use warnings; use Log::Log4perl::Level; use Log::Log4perl::Config; use Log::Log4perl::Util qw( params_check ); use constant _INTERNAL_DEBUG => 0; use base "Log::Log4perl::Filter"; ################################################## sub new { ################################################## my ($class, %options) = @_; my $self = { LevelMin => 'DEBUG', LevelMax => 'FATAL', AcceptOnMatch => 1, %options, }; params_check( $self, [ qw( LevelMin LevelMax ) ], [ qw( name AcceptOnMatch ) ] ); $self->{AcceptOnMatch} = Log::Log4perl::Config::boolean_to_perlish( $self->{AcceptOnMatch}); bless $self, $class; return $self; } ################################################## sub ok { ################################################## my ($self, %p) = @_; if(Log::Log4perl::Level::to_priority($self->{LevelMin}) <= Log::Log4perl::Level::to_priority($p{log4p_level}) and Log::Log4perl::Level::to_priority($self->{LevelMax}) >= Log::Log4perl::Level::to_priority($p{log4p_level})) { return $self->{AcceptOnMatch}; } else { return ! $self->{AcceptOnMatch}; } } 1; __END__ =encoding utf8 =head1 NAME Log::Log4perl::Filter::LevelRange - Filter for a range of log levels =head1 SYNOPSIS log4perl.filter.Match1 = Log::Log4perl::Filter::LevelRange log4perl.filter.Match1.LevelMin = INFO log4perl.filter.Match1.LevelMax = ERROR log4perl.filter.Match1.AcceptOnMatch = true =head1 DESCRIPTION This Log4perl custom filter checks if the current message has a priority matching a predefined range. The C and C parameters define the levels (choose from C, C, C, C, C) marking the window of allowed messages priorities. C defaults to C, and C to C. The additional parameter C defines if the filter is supposed to pass or block the message (C or C). =head1 SEE ALSO L, L, L, L, L =head1 LICENSE Copyright 2002-2013 by Mike Schilli Em@perlmeister.comE and Kevin Goess Ecpan@goess.orgE. This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =head1 AUTHOR Please contribute patches to the project on Github: http://github.com/mschilli/log4perl Send bug reports or requests for enhancements to the authors via our MAILING LIST (questions, bug reports, suggestions/patches): log4perl-devel@lists.sourceforge.net Authors (please contact them via the list above, not directly): Mike Schilli , Kevin Goess Contributors (in alphabetical order): Ateeq Altaf, Cory Bennett, Jens Berthold, Jeremy Bopp, Hutton Davidson, Chris R. Donnelly, Matisse Enzer, Hugh Esco, Anthony Foiani, James FitzGibbon, Carl Franks, Dennis Gregorovic, Andy Grundman, Paul Harrington, Alexander Hartmaier David Hull, Robert Jacobson, Jason Kohles, Jeff Macdonald, Markus Peter, Brett Rann, Peter Rabbitson, Erik Selberg, Aaron Straup Cope, Lars Thegler, David Viner, Mac Yang. MDC.pm000064400000004552147635410140005520 0ustar00package Log::Log4perl::Filter::MDC; use strict; use warnings; use Log::Log4perl::Util qw( params_check ); use base "Log::Log4perl::Filter"; sub new { my ( $class, %options ) = @_; my $self = {%options}; params_check( $self, [qw( KeyToMatch RegexToMatch )] ); $self->{RegexToMatch} = qr/$self->{RegexToMatch}/; bless $self, $class; return $self; } sub ok { my ( $self, %p ) = @_; my $context = Log::Log4perl::MDC->get_context; my $value = $context->{ $self->{KeyToMatch} }; return 1 if defined $value && $value =~ $self->{RegexToMatch}; return 0; } 1; __END__ =encoding utf8 =head1 NAME Log::Log4perl::Filter::MDC - Filter to match on values of a MDC key =head1 SYNOPSIS log4perl.filter.Match1 = Log::Log4perl::Filter::MDC log4perl.filter.Match1.KeyToMatch = foo log4perl.filter.Match1.RegexToMatch = bar =head1 DESCRIPTION This Log4perl filter checks if a predefined MDC key, as set in C, of the currently submitted message matches a predefined regex, as set in C. =head1 SEE ALSO L, L, L, L, L, L =head1 LICENSE Copyright 2002-2013 by Mike Schilli Em@perlmeister.comE and Kevin Goess Ecpan@goess.orgE. This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =head1 AUTHOR Please contribute patches to the project on Github: http://github.com/mschilli/log4perl Send bug reports or requests for enhancements to the authors via our MAILING LIST (questions, bug reports, suggestions/patches): log4perl-devel@lists.sourceforge.net Authors (please contact them via the list above, not directly): Mike Schilli , Kevin Goess Contributors (in alphabetical order): Ateeq Altaf, Cory Bennett, Jens Berthold, Jeremy Bopp, Hutton Davidson, Chris R. Donnelly, Matisse Enzer, Hugh Esco, Anthony Foiani, James FitzGibbon, Carl Franks, Dennis Gregorovic, Andy Grundman, Paul Harrington, Alexander Hartmaier David Hull, Robert Jacobson, Jason Kohles, Jeff Macdonald, Markus Peter, Brett Rann, Peter Rabbitson, Erik Selberg, Aaron Straup Cope, Lars Thegler, David Viner, Mac Yang. Boolean.pm000064400000014572147635410140006477 0ustar00################################################## package Log::Log4perl::Filter::Boolean; ################################################## use 5.006; use strict; use warnings; use Log::Log4perl::Level; use Log::Log4perl::Config; use constant _INTERNAL_DEBUG => 0; use base qw(Log::Log4perl::Filter); ################################################## sub new { ################################################## my ($class, %options) = @_; my $self = { params => {}, %options, }; bless $self, $class; print "Compiling '$options{logic}'\n" if _INTERNAL_DEBUG; # Set up meta-decider for later $self->compile_logic($options{logic}); return $self; } ################################################## sub ok { ################################################## my ($self, %p) = @_; return $self->eval_logic(\%p); } ################################################## sub compile_logic { ################################################## my ($self, $logic) = @_; # Extract Filter placeholders in logic as defined # in configuration file. while($logic =~ /([\w_-]+)/g) { # Get the corresponding filter object my $filter = Log::Log4perl::Filter::by_name($1); die "Filter $filter required by Boolean filter, but not defined" unless $filter; $self->{params}->{$1} = $filter; } # Fabricate a parameter list: A1/A2/A3 => $A1, $A2, $A3 my $plist = join ', ', map { '$' . $_ } keys %{$self->{params}}; # Replace all the (dollar-less) placeholders in the code # by scalars (basically just put dollars in front of them) $logic =~ s/([\w_-]+)/\$$1/g; # Set up the meta decider, which transforms the config file # logic into compiled perl code my $func = <{eval_func} = $eval_func; } ################################################## sub eval_logic { ################################################## my($self, $p) = @_; my @plist = (); # Eval the results of all filters referenced # in the code (although the order of keys is # not predictable, it is consistent :) for my $param (keys %{$self->{params}}) { # Call ok() and map the result to 1 or 0 print "Calling filter $param\n" if _INTERNAL_DEBUG; push @plist, ($self->{params}->{$param}->ok(%$p) ? 1 : 0); } # Now pipe the parameters into the canned function, # have it evaluate the logic and return the final # decision print "Passing in (", join(', ', @plist), ")\n" if _INTERNAL_DEBUG; return $self->{eval_func}->(@plist); } 1; __END__ =encoding utf8 =head1 NAME Log::Log4perl::Filter::Boolean - Special filter to combine the results of others =head1 SYNOPSIS log4perl.logger = WARN, AppWarn, AppError log4perl.filter.Match1 = sub { /let this through/ } log4perl.filter.Match2 = sub { /and that, too/ } log4perl.filter.MyBoolean = Log::Log4perl::Filter::Boolean log4perl.filter.MyBoolean.logic = Match1 || Match2 log4perl.appender.Screen = Log::Dispatch::Screen log4perl.appender.Screen.Filter = MyBoolean log4perl.appender.Screen.layout = Log::Log4perl::Layout::SimpleLayout =head1 DESCRIPTION Sometimes, it's useful to combine the output of various filters to arrive at a log/no log decision. While Log4j, Log4perl's mother ship, chose to implement this feature as a filter chain, similar to Linux' IP chains, Log4perl tries a different approach. Typically, filter results will not need to be passed along in chains but combined in a programmatic manner using boolean logic. "Log if this filter says 'yes' and that filter says 'no'" is a fairly common requirement but hard to implement as a chain. C is a special predefined custom filter for Log4perl which combines the results of other custom filters in arbitrary ways, using boolean expressions: log4perl.logger = WARN, AppWarn, AppError log4perl.filter.Match1 = sub { /let this through/ } log4perl.filter.Match2 = sub { /and that, too/ } log4perl.filter.MyBoolean = Log::Log4perl::Filter::Boolean log4perl.filter.MyBoolean.logic = Match1 || Match2 log4perl.appender.Screen = Log::Dispatch::Screen log4perl.appender.Screen.Filter = MyBoolean log4perl.appender.Screen.layout = Log::Log4perl::Layout::SimpleLayout C's boolean expressions allow for combining different appenders by name using AND (&& or &), OR (|| or |) and NOT (!) as logical expressions. Parentheses are used for grouping. Precedence follows standard Perl. Here's a bunch of examples: Match1 && !Match2 # Match1 and not Match2 !(Match1 || Match2) # Neither Match1 nor Match2 (Match1 && Match2) || Match3 # Both Match1 and Match2 or Match3 =head1 SEE ALSO L, L, L, L, L =head1 LICENSE Copyright 2002-2013 by Mike Schilli Em@perlmeister.comE and Kevin Goess Ecpan@goess.orgE. This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =head1 AUTHOR Please contribute patches to the project on Github: http://github.com/mschilli/log4perl Send bug reports or requests for enhancements to the authors via our MAILING LIST (questions, bug reports, suggestions/patches): log4perl-devel@lists.sourceforge.net Authors (please contact them via the list above, not directly): Mike Schilli , Kevin Goess Contributors (in alphabetical order): Ateeq Altaf, Cory Bennett, Jens Berthold, Jeremy Bopp, Hutton Davidson, Chris R. Donnelly, Matisse Enzer, Hugh Esco, Anthony Foiani, James FitzGibbon, Carl Franks, Dennis Gregorovic, Andy Grundman, Paul Harrington, Alexander Hartmaier David Hull, Robert Jacobson, Jason Kohles, Jeff Macdonald, Markus Peter, Brett Rann, Peter Rabbitson, Erik Selberg, Aaron Straup Cope, Lars Thegler, David Viner, Mac Yang. LevelMatch.pm000064400000006243147635410140007140 0ustar00################################################## package Log::Log4perl::Filter::LevelMatch; ################################################## use 5.006; use strict; use warnings; use Log::Log4perl::Level; use Log::Log4perl::Config; use Log::Log4perl::Util qw( params_check ); use constant _INTERNAL_DEBUG => 0; use base qw(Log::Log4perl::Filter); ################################################## sub new { ################################################## my ($class, %options) = @_; my $self = { LevelToMatch => '', AcceptOnMatch => 1, %options, }; params_check( $self, [ qw( LevelToMatch ) ], [ qw( name AcceptOnMatch ) ] ); $self->{AcceptOnMatch} = Log::Log4perl::Config::boolean_to_perlish( $self->{AcceptOnMatch}); bless $self, $class; return $self; } ################################################## sub ok { ################################################## my ($self, %p) = @_; if($self->{LevelToMatch} eq $p{log4p_level}) { print "Levels match\n" if _INTERNAL_DEBUG; return $self->{AcceptOnMatch}; } else { print "Levels don't match\n" if _INTERNAL_DEBUG; return !$self->{AcceptOnMatch}; } } 1; __END__ =encoding utf8 =head1 NAME Log::Log4perl::Filter::LevelMatch - Filter to match the log level exactly =head1 SYNOPSIS log4perl.filter.Match1 = Log::Log4perl::Filter::LevelMatch log4perl.filter.Match1.LevelToMatch = ERROR log4perl.filter.Match1.AcceptOnMatch = true =head1 DESCRIPTION This Log4perl custom filter checks if the currently submitted message matches a predefined priority, as set in C. The additional parameter C defines if the filter is supposed to pass or block the message (C or C) on a match. =head1 SEE ALSO L, L, L, L, L =head1 LICENSE Copyright 2002-2013 by Mike Schilli Em@perlmeister.comE and Kevin Goess Ecpan@goess.orgE. This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =head1 AUTHOR Please contribute patches to the project on Github: http://github.com/mschilli/log4perl Send bug reports or requests for enhancements to the authors via our MAILING LIST (questions, bug reports, suggestions/patches): log4perl-devel@lists.sourceforge.net Authors (please contact them via the list above, not directly): Mike Schilli , Kevin Goess Contributors (in alphabetical order): Ateeq Altaf, Cory Bennett, Jens Berthold, Jeremy Bopp, Hutton Davidson, Chris R. Donnelly, Matisse Enzer, Hugh Esco, Anthony Foiani, James FitzGibbon, Carl Franks, Dennis Gregorovic, Andy Grundman, Paul Harrington, Alexander Hartmaier David Hull, Robert Jacobson, Jason Kohles, Jeff Macdonald, Markus Peter, Brett Rann, Peter Rabbitson, Erik Selberg, Aaron Straup Cope, Lars Thegler, David Viner, Mac Yang. StringMatch.pm000064400000006674147635410140007347 0ustar00################################################## package Log::Log4perl::Filter::StringMatch; ################################################## use 5.006; use strict; use warnings; use Log::Log4perl::Config; use Log::Log4perl::Util qw( params_check ); use constant _INTERNAL_DEBUG => 0; use base "Log::Log4perl::Filter"; ################################################## sub new { ################################################## my ($class, %options) = @_; print join('-', %options) if _INTERNAL_DEBUG; my $self = { StringToMatch => undef, AcceptOnMatch => 1, %options, }; params_check( $self, [ qw( StringToMatch ) ], [ qw( name AcceptOnMatch ) ] ); $self->{AcceptOnMatch} = Log::Log4perl::Config::boolean_to_perlish( $self->{AcceptOnMatch}); $self->{StringToMatch} = qr($self->{StringToMatch}); bless $self, $class; return $self; } ################################################## sub ok { ################################################## my ($self, %p) = @_; local($_) = join $ Log::Log4perl::JOIN_MSG_ARRAY_CHAR, @{$p{message}}; if($_ =~ $self->{StringToMatch}) { print "Strings match\n" if _INTERNAL_DEBUG; return $self->{AcceptOnMatch}; } else { print "Strings don't match ($_/$self->{StringToMatch})\n" if _INTERNAL_DEBUG; return !$self->{AcceptOnMatch}; } } 1; __END__ =encoding utf8 =head1 NAME Log::Log4perl::Filter::StringMatch - Filter on log message string =head1 SYNOPSIS log4perl.filter.Match1 = Log::Log4perl::Filter::StringMatch log4perl.filter.Match1.StringToMatch = blah blah log4perl.filter.Match1.AcceptOnMatch = true =head1 DESCRIPTION This Log4perl custom filter checks if the currently submitted message matches a predefined regular expression, as set in the C parameter. It uses common Perl 5 regexes. The additional parameter C defines if the filter is supposed to pass or block the message on a match (C or C). =head1 SEE ALSO L, L, L, L, L =head1 LICENSE Copyright 2002-2013 by Mike Schilli Em@perlmeister.comE and Kevin Goess Ecpan@goess.orgE. This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =head1 AUTHOR Please contribute patches to the project on Github: http://github.com/mschilli/log4perl Send bug reports or requests for enhancements to the authors via our MAILING LIST (questions, bug reports, suggestions/patches): log4perl-devel@lists.sourceforge.net Authors (please contact them via the list above, not directly): Mike Schilli , Kevin Goess Contributors (in alphabetical order): Ateeq Altaf, Cory Bennett, Jens Berthold, Jeremy Bopp, Hutton Davidson, Chris R. Donnelly, Matisse Enzer, Hugh Esco, Anthony Foiani, James FitzGibbon, Carl Franks, Dennis Gregorovic, Andy Grundman, Paul Harrington, Alexander Hartmaier David Hull, Robert Jacobson, Jason Kohles, Jeff Macdonald, Markus Peter, Brett Rann, Peter Rabbitson, Erik Selberg, Aaron Straup Cope, Lars Thegler, David Viner, Mac Yang.