| 1 | package Log::Log4perl::Filter::CallerMatch; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 2 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 3 | 2 | $Log::Log4perl::Filter::CallerMatch::VERSION = '1.200'; | |||||||||||||||||||||||||||||||||||||||||
| 4 | } | ||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | # ABSTRACT: Filter Log4perl messages based on call frames | ||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use 5.006; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use Log::Log4perl::Config; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use base 'Log::Log4perl::Filter'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 2 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | 12 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | 12 | my ( $class, %options ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | 12 | my $self = { | |||||||||||||||||||||||||||||||||||||||||
| 19 | AcceptOnMatch => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 20 | MinCallFrame => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 21 | MaxCallFrame => 5, | ||||||||||||||||||||||||||||||||||||||||||
| 22 | %options, | ||||||||||||||||||||||||||||||||||||||||||
| 23 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | 12 | $self->{AcceptOnMatch} = Log::Log4perl::Config::boolean_to_perlish( $self->{AcceptOnMatch} ); | |||||||||||||||||||||||||||||||||||||||||
| 26 | 12 | ▶ | $self->{SubToMatch} = defined $self->{SubToMatch} ? qr($self->{SubToMatch}) : qr/.*/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | 12 | ▶ | $self->{PackageToMatch} = defined $self->{PackageToMatch} ? qr($self->{PackageToMatch}) : qr/.*/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | 12 | ▶ | $self->{StringToMatch} = defined $self->{StringToMatch} ? qr($self->{StringToMatch}) : qr/.*/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | 12 | ▶ | if ( defined $self->{CallFrame} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | 2 | $self->{MinCallFrame} = $self->{MaxCallFrame} = $self->{CallFrame}; | |||||||||||||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | 12 | bless $self, $class; | |||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | 12 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | 16 | ▶ | sub ok { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ok: called CC=8 SCAR=20.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 41 | 16 | my ( $self, %p ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | 16 | my $message = join $Log::Log4perl::JOIN_MSG_ARRAY_CHAR, @{ $p{message} }; | |||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | 16 | my ( $s_regex, $p_regex, $m_regex ) = ( $self->{SubToMatch}, $self->{PackageToMatch}, $self->{StringToMatch} ); | |||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | # First climb out of Log4perl's internals (differs depending on whether Boolean is being used etc.. | ||||||||||||||||||||||||||||||||||||||||||
| 48 | 16 | my $base = 0; | |||||||||||||||||||||||||||||||||||||||||
| 49 | 16 | ▶ | $base++ while caller($base) =~ m/^Log::Log4perl/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||
| 51 | 16 | foreach my $i ( $self->{MinCallFrame} .. $self->{MaxCallFrame} ) { | |||||||||||||||||||||||||||||||||||||||||
| 52 | 44 | my ( $package, $sub ) = ( caller $i + $base )[ 0, 3 ]; | |||||||||||||||||||||||||||||||||||||||||
| 53 | 44 | ▶ | next unless $package; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | 16 | ▶ | next unless $sub; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | 2 | ▶ | no warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | 16 | ▶ | if ( $sub =~ $s_regex && $package =~ $p_regex && $message =~ $m_regex ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$sub =~ /$s_regex/ and $package =~ /$p_regex/ and $message =~ /$m_regex/
$sub =~ /$s_regex/ and $package =~ /$p_regex/
MC/DC100%3/3
$sub =~ /$s_regex/ and $package =~ /$p_regex/ and $message =~ /$m_regex/
$sub =~ /$s_regex/
$package =~ /$p_regex/
$message =~ /$m_regex/
Truth table100%4/4
A and B and C
A= $sub =~ /$s_regex/B= $package =~ /$p_regex/C= $message =~ /$m_regex/
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | 9 | return $self->{AcceptOnMatch}; | |||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||||||||
| 60 | 7 | return !$self->{AcceptOnMatch}; | |||||||||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||
| 66 | =pod | ||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||
| 70 | Log::Log4perl::Filter::CallerMatch - Filter Log4perl messages based on call frames | ||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | =head1 VERSION | ||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | version 1.200 | ||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||
| 76 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||
| 78 | This Log4perl custom filter checks the call stack using caller() and filters | ||||||||||||||||||||||||||||||||||||||||||
| 79 | the subroutine and package using user-provided regular expressions. You can specify | ||||||||||||||||||||||||||||||||||||||||||
| 80 | a specific call frame to test against, or have the filter iterate through a range of call frames. | ||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||
| 82 | =head1 ATTRIBUTES | ||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | =head2 StringToMatch | ||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||
| 86 | A perl5 regular expression, matched against the log message. | ||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | =head2 AcceptOnMatch | ||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||
| 90 | Defines if the filter is supposed to pass or block the message on a match (C<true> or C<false>). | ||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||
| 92 | =head2 PackageToMatch | ||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||
| 94 | A perl5 regular expression, matched against the 1st item in the array returned by caller() (e.g. "package") | ||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||
| 96 | =head2 SubToMatch | ||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||
| 98 | A perl5 regular expression, matched against the 4th item in the array returned by caller() (e.g. "subroutine") | ||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | =head2 CallFrame | ||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||
| 102 | The call frame to use when requesting information from caller(). (e.g. $i in caller($i) | ||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||
| 104 | =head2 MinCallFrame | ||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||
| 106 | The first call frame tested against when iterating through a series of call frames. Ignored if CallFrame specified. | ||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||
| 108 | =head2 MaxCallFrame | ||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||
| 110 | The last call frame tested against when iterating through a series of call frames. Ignored if CallFrame specified. | ||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||
| 112 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||
| 114 | =head2 new | ||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||
| 116 | Constructor. Refer to L<Log::Log4perl::Filter> for more information | ||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||
| 118 | =head2 ok | ||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||
| 120 | Decides whether log message should be accepted or not. Refer to L<Log::Log4perl::Filter> for more information | ||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||
| 122 | =head1 USAGE | ||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||
| 124 | # log.conf | ||||||||||||||||||||||||||||||||||||||||||
| 125 | log4perl.logger = ALL, A1 | ||||||||||||||||||||||||||||||||||||||||||
| 126 | log4perl.appender.A1 = Log::Log4perl::Appender::TestBuffer | ||||||||||||||||||||||||||||||||||||||||||
| 127 | log4perl.appender.A1.Filter = MyFilter | ||||||||||||||||||||||||||||||||||||||||||
| 128 | log4perl.appender.A1.layout = Log::Log4perl::Layout::SimpleLayout | ||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||
| 130 | log4perl.filter.MyFilter = Log::Log4perl::Filter::CallerMatch | ||||||||||||||||||||||||||||||||||||||||||
| 131 | log4perl.filter.MyFilter.SubToMatch = WebGUI::Session::ErrorHandler | ||||||||||||||||||||||||||||||||||||||||||
| 132 | log4perl.filter.MyFilter.PackageToMatch = Flux:: | ||||||||||||||||||||||||||||||||||||||||||
| 133 | log4perl.filter.MyFilter.StringToMatch = Operand1 | ||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||
| 135 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||
| 137 | L<Log::Log4perl::Filter>, | ||||||||||||||||||||||||||||||||||||||||||
| 138 | L<Log::Log4perl::Filter::StringMatch>, | ||||||||||||||||||||||||||||||||||||||||||
| 139 | L<Log::Log4perl::Filter::LevelMatch>, | ||||||||||||||||||||||||||||||||||||||||||
| 140 | L<Log::Log4perl::Filter::LevelRange>, | ||||||||||||||||||||||||||||||||||||||||||
| 141 | L<Log::Log4perl::Filter::Boolean> | ||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||
| 143 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||
| 145 | Patrick Donelan <pdonelan@cpan.org> | ||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||
| 147 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||
| 149 | This software is copyright (c) 2010 by Patrick Donelan. | ||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||
| 151 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||||||||||||||||
| 152 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||
| 154 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||
| 157 | __END__ | ||||||||||||||||||||||||||||||||||||||||||