home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / tsw / TSW_3.4.0.exe / Apache2 / perl / LevelRange.pm < prev    next >
Encoding:
Perl POD Document  |  2003-03-14  |  2.2 KB  |  88 lines

  1. ##################################################
  2. package Log::Log4perl::Filter::LevelRange;
  3. ##################################################
  4.  
  5. use 5.006;
  6.  
  7. use strict;
  8. use warnings;
  9.  
  10. use Log::Log4perl::Level;
  11. use Log::Log4perl::Config;
  12.  
  13. use constant DEBUG => 0;
  14.  
  15. use base "Log::Log4perl::Filter";
  16.  
  17. ##################################################
  18. sub 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. ##################################################
  37. sub 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.  
  51. 1;
  52.  
  53. __END__
  54.  
  55. =head1 NAME
  56.  
  57. Log::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.  
  68. This Log4perl custom filter checks if the current message
  69. has a priority matching a predefined range. 
  70. The C<LevelMin> and C<LevelMax> parameters define the levels
  71. (choose from C<DEBUG>, C<INFO>, C<WARN>, C<ERROR>, C<FATAL>) marking
  72. the window of allowed messages priorities.
  73. The additional parameter C<AcceptOnMatch> defines if the filter
  74. is supposed to pass or block the message (C<true> or C<false>).
  75.  
  76. =head1 SEE ALSO
  77.  
  78. L<Log::Log4perl::Filter>,
  79. L<Log::Log4perl::Filter::LevelMatch>,
  80. L<Log::Log4perl::Filter::StringRange>,
  81. L<Log::Log4perl::Filter::Boolean>
  82.  
  83. =head1 AUTHOR
  84.  
  85. Mike Schilli, E<lt>log4perl@perlmeister.comE<gt>, 2003
  86.  
  87. =cut
  88.