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;
12
13use constant _INTERNAL_DEBUG => 0;
14
15use base "Log::Log4perl::Filter";
16
17##################################################
18sub new {
19##################################################
20    my ($class, %options) = @_;
21
22    my $self = { LevelMin      => 'DEBUG',
23                 LevelMax      => 'FATAL',
24                 AcceptOnMatch => 1,
25                 %options,
26               };
27
28    $self->{AcceptOnMatch} = Log::Log4perl::Config::boolean_to_perlish(
29                                                $self->{AcceptOnMatch});
30
31    bless $self, $class;
32
33    return $self;
34}
35
36##################################################
37sub ok {
38##################################################
39     my ($self, %p) = @_;
40
41     if(Log::Log4perl::Level::to_priority($self->{LevelMin}) <=
42        Log::Log4perl::Level::to_priority($p{log4p_level}) and
43        Log::Log4perl::Level::to_priority($self->{LevelMax}) >=
44        Log::Log4perl::Level::to_priority($p{log4p_level})) {
45         return $self->{AcceptOnMatch};
46     } else {
47         return ! $self->{AcceptOnMatch};
48     }
49}
50
511;
52
53__END__
54
55=head1 NAME
56
57Log::Log4perl::Filter::LevelRange - Filter for a range of log levels
58
59=head1 SYNOPSIS
60
61    log4perl.filter.Match1               = Log::Log4perl::Filter::LevelRange
62    log4perl.filter.Match1.LevelMin      = INFO
63    log4perl.filter.Match1.LevelMax      = ERROR
64    log4perl.filter.Match1.AcceptOnMatch = true
65
66=head1 DESCRIPTION
67
68This Log4perl custom filter checks if the current message
69has a priority matching a predefined range.
70The C<LevelMin> and C<LevelMax> parameters define the levels
71(choose from C<DEBUG>, C<INFO>, C<WARN>, C<ERROR>, C<FATAL>) marking
72the window of allowed messages priorities.
73The additional parameter C<AcceptOnMatch> defines if the filter
74is supposed to pass or block the message (C<true> or C<false>).
75
76=head1 SEE ALSO
77
78L<Log::Log4perl::Filter>,
79L<Log::Log4perl::Filter::LevelMatch>,
80L<Log::Log4perl::Filter::StringRange>,
81L<Log::Log4perl::Filter::Boolean>
82
83=head1 AUTHOR
84
85Mike Schilli, E<lt>log4perl@perlmeister.comE<gt>, 2003
86
87=cut
88