File Coverage

blib/lib/Log/Log4perl/Filter/MDC.pm
Criterion Covered Total %
statement 23 23 100.0
branch 2 2 100.0
condition 2 3 66.6
subroutine 6 6 100.0
pod 0 2 0.0
total 33 36 91.6


line stmt bran cond sub pod time code
1             use strict;
2 1     1   6 use warnings;
  1         2  
  1         22  
3 1     1   4  
  1         1  
  1         21  
4             use Log::Log4perl::Util qw( params_check );
5 1     1   3  
  1         2  
  1         33  
6             use base "Log::Log4perl::Filter";
7 1     1   4  
  1         2  
  1         197  
8             my ( $class, %options ) = @_;
9              
10 1     1 0 4 my $self = {%options};
11              
12 1         3 params_check( $self, [qw( KeyToMatch RegexToMatch )] );
13              
14 1         3 $self->{RegexToMatch} = qr/$self->{RegexToMatch}/;
15              
16 1         15 bless $self, $class;
17              
18 1         2 return $self;
19             }
20 1         3  
21             my ( $self, %p ) = @_;
22              
23             my $context = Log::Log4perl::MDC->get_context;
24 2     2 0 5  
25             my $value = $context->{ $self->{KeyToMatch} };
26 2         6 return 1
27             if defined $value && $value =~ $self->{RegexToMatch};
28 2         3  
29             return 0;
30 2 100 66     11 }
31              
32 1         3 1;
33              
34              
35             =encoding utf8
36              
37             =head1 NAME
38              
39             Log::Log4perl::Filter::MDC - Filter to match on values of a MDC key
40              
41             =head1 SYNOPSIS
42              
43             log4perl.filter.Match1 = Log::Log4perl::Filter::MDC
44             log4perl.filter.Match1.KeyToMatch = foo
45             log4perl.filter.Match1.RegexToMatch = bar
46              
47             =head1 DESCRIPTION
48              
49             This Log4perl filter checks if a predefined MDC key, as set in C<KeyToMatch>,
50             of the currently submitted message matches a predefined regex, as set in
51             C<RegexToMatch>.
52              
53             =head1 SEE ALSO
54              
55             L<Log::Log4perl::Filter>,
56             L<Log::Log4perl::Filter::Boolean>,
57             L<Log::Log4perl::Filter::LevelMatch>,
58             L<Log::Log4perl::Filter::LevelRange>,
59             L<Log::Log4perl::Filter::MDC>,
60             L<Log::Log4perl::Filter::StringMatch>
61              
62             =head1 LICENSE
63              
64             Copyright 2002-2013 by Mike Schilli E<lt>m@perlmeister.comE<gt>
65             and Kevin Goess E<lt>cpan@goess.orgE<gt>.
66              
67             This library is free software; you can redistribute it and/or modify
68             it under the same terms as Perl itself.
69              
70             =head1 AUTHOR
71              
72             Please contribute patches to the project on Github:
73              
74             http://github.com/mschilli/log4perl
75              
76             Send bug reports or requests for enhancements to the authors via our
77              
78             MAILING LIST (questions, bug reports, suggestions/patches):
79             log4perl-devel@lists.sourceforge.net
80              
81             Authors (please contact them via the list above, not directly):
82             Mike Schilli <m@perlmeister.com>,
83             Kevin Goess <cpan@goess.org>
84              
85             Contributors (in alphabetical order):
86             Ateeq Altaf, Cory Bennett, Jens Berthold, Jeremy Bopp, Hutton
87             Davidson, Chris R. Donnelly, Matisse Enzer, Hugh Esco, Anthony
88             Foiani, James FitzGibbon, Carl Franks, Dennis Gregorovic, Andy
89             Grundman, Paul Harrington, Alexander Hartmaier David Hull,
90             Robert Jacobson, Jason Kohles, Jeff Macdonald, Markus Peter,
91             Brett Rann, Peter Rabbitson, Erik Selberg, Aaron Straup Cope,
92             Lars Thegler, David Viner, Mac Yang.
93