1##################################################
2package Log::Log4perl::Filter::LevelRange;
3##################################################
4
5use 5.006;
6
7use strict;
8use warnings;
9
10use Log::Log4perl::Level;
11use Log::Log4perl::Config;
12use Log::Log4perl::Util qw( params_check );
13
14use constant _INTERNAL_DEBUG => 0;
15
16use base "Log::Log4perl::Filter";
17
18##################################################
19sub new {
20##################################################
21    my ($class, %options) = @_;
22
23    my $self = { LevelMin      => 'DEBUG',
24                 LevelMax      => 'FATAL',
25                 AcceptOnMatch => 1,
26                 %options,
27               };
28
29    params_check( $self,
30                  [ qw( LevelMin LevelMax ) ],
31                  [ qw( name AcceptOnMatch ) ]
32                );
33
34    $self->{AcceptOnMatch} = Log::Log4perl::Config::boolean_to_perlish(
35                                                $self->{AcceptOnMatch});
36
37    bless $self, $class;
38
39    return $self;
40}
41
42##################################################
43sub ok {
44##################################################
45     my ($self, %p) = @_;
46
47     if(Log::Log4perl::Level::to_priority($self->{LevelMin}) <=
48        Log::Log4perl::Level::to_priority($p{log4p_level}) and
49        Log::Log4perl::Level::to_priority($self->{LevelMax}) >=
50        Log::Log4perl::Level::to_priority($p{log4p_level})) {
51         return $self->{AcceptOnMatch};
52     } else {
53         return ! $self->{AcceptOnMatch};
54     }
55}
56
571;
58
59__END__
60
61=head1 NAME
62
63Log::Log4perl::Filter::LevelRange - Filter for a range of log levels
64
65=head1 SYNOPSIS
66
67    log4perl.filter.Match1               = Log::Log4perl::Filter::LevelRange
68    log4perl.filter.Match1.LevelMin      = INFO
69    log4perl.filter.Match1.LevelMax      = ERROR
70    log4perl.filter.Match1.AcceptOnMatch = true
71
72=head1 DESCRIPTION
73
74This Log4perl custom filter checks if the current message
75has a priority matching a predefined range.
76The C<LevelMin> and C<LevelMax> parameters define the levels
77(choose from C<DEBUG>, C<INFO>, C<WARN>, C<ERROR>, C<FATAL>) marking
78the window of allowed messages priorities.
79
80C<LevelMin> defaults to C<DEBUG>, and C<LevelMax> to C<FATAL>.
81
82The additional parameter C<AcceptOnMatch> defines if the filter
83is supposed to pass or block the message (C<true> or C<false>).
84
85=head1 SEE ALSO
86
87L<Log::Log4perl::Filter>,
88L<Log::Log4perl::Filter::LevelMatch>,
89L<Log::Log4perl::Filter::StringRange>,
90L<Log::Log4perl::Filter::Boolean>
91
92=head1 LICENSE
93
94Copyright 2002-2012 by Mike Schilli E<lt>m@perlmeister.comE<gt>
95and Kevin Goess E<lt>cpan@goess.orgE<gt>.
96
97This library is free software; you can redistribute it and/or modify
98it under the same terms as Perl itself.
99
100=head1 AUTHOR
101
102Please contribute patches to the project on Github:
103
104    http://github.com/mschilli/log4perl
105
106Send bug reports or requests for enhancements to the authors via our
107
108MAILING LIST (questions, bug reports, suggestions/patches):
109log4perl-devel@lists.sourceforge.net
110
111Authors (please contact them via the list above, not directly):
112Mike Schilli <m@perlmeister.com>,
113Kevin Goess <cpan@goess.org>
114
115Contributors (in alphabetical order):
116Ateeq Altaf, Cory Bennett, Jens Berthold, Jeremy Bopp, Hutton
117Davidson, Chris R. Donnelly, Matisse Enzer, Hugh Esco, Anthony
118Foiani, James FitzGibbon, Carl Franks, Dennis Gregorovic, Andy
119Grundman, Paul Harrington, David Hull, Robert Jacobson, Jason Kohles,
120Jeff Macdonald, Markus Peter, Brett Rann, Peter Rabbitson, Erik
121Selberg, Aaron Straup Cope, Lars Thegler, David Viner, Mac Yang.
122
123