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 / ApacheLog.pm < prev    next >
Encoding:
Perl POD Document  |  2003-09-27  |  3.0 KB  |  147 lines

  1. package Log::Dispatch::ApacheLog;
  2.  
  3. use strict;
  4.  
  5. use Log::Dispatch::Output;
  6.  
  7. use base qw( Log::Dispatch::Output );
  8.  
  9. use Params::Validate qw(validate);
  10. Params::Validate::validation_options( allow_extra => 1 );
  11.  
  12. use Apache::Log;
  13.  
  14. use vars qw[ $VERSION ];
  15.  
  16. $VERSION = sprintf "%d.%02d", q$Revision: 1.9 $ =~ /: (\d+)\.(\d+)/;
  17.  
  18. 1;
  19.  
  20. sub new
  21. {
  22.     my $proto = shift;
  23.     my $class = ref $proto || $proto;
  24.  
  25.     my %p = validate( @_, { apache => { can => 'log' } } );
  26.  
  27.     my $self = bless {}, $class;
  28.  
  29.     $self->_basic_init(%p);
  30.     $self->{apache_log} = $p{apache}->log;
  31.  
  32.     return $self;
  33. }
  34.  
  35. sub log_message
  36. {
  37.     my $self = shift;
  38.     my %p = @_;
  39.  
  40.     my $method;
  41.  
  42.     my $level = $self->_level_as_name($p{level});
  43.     if ($level eq 'emergency')
  44.     {
  45.     $method = 'emerg';
  46.     }
  47.     elsif ( $level eq 'critical' )
  48.     {
  49.     $method = 'crit';
  50.     }
  51.     elsif( $level eq 'err' )
  52.     {
  53.     $method = 'error';
  54.     }
  55.     elsif( $level eq 'warning' )
  56.     {
  57.     $method = 'warn';
  58.     }
  59.     else
  60.     {
  61.     $method = $level;
  62.     }
  63.  
  64.     $self->{apache_log}->$method( $p{message} );
  65. }
  66.  
  67. __END__
  68.  
  69. =head1 NAME
  70.  
  71. Log::Dispatch::ApacheLog - Object for logging to Apache::Log objects
  72.  
  73. =head1 SYNOPSIS
  74.  
  75.   use Log::Dispatch::ApacheLog;
  76.  
  77.   my $handle = Log::Dispatch::ApacheLog->new( name      => 'apache log',
  78.                                               min_level => 'emerg',
  79.                                               apache    => $r );
  80.  
  81.   $handle->log( level => 'emerg', message => 'Kaboom' );
  82.  
  83. =head1 DESCRIPTION
  84.  
  85. This module allows you to pass messages Apache's log object,
  86. represented by the Apache::Log class.
  87.  
  88. =head1 METHODS
  89.  
  90. =over 4
  91.  
  92. =item * new(%p)
  93.  
  94. This method takes a hash of parameters.  The following options are
  95. valid:
  96.  
  97. =over 8
  98.  
  99. =item * name ($)
  100.  
  101. The name of the object (not the filename!).  Required.
  102.  
  103. =item * min_level ($)
  104.  
  105. The minimum logging level this object will accept.  See the
  106. Log::Dispatch documentation for more information.  Required.
  107.  
  108. =item * max_level ($)
  109.  
  110. The maximum logging level this obejct will accept.  See the
  111. Log::Dispatch documentation for more information.  This is not
  112. required.  By default the maximum is the highest possible level (which
  113. means functionally that the object has no maximum).
  114.  
  115. =item * apache ($)
  116.  
  117. An object of either the Apache or Apache::Server classes.
  118.  
  119. =item * callbacks( \& or [ \&, \&, ... ] )
  120.  
  121. This parameter may be a single subroutine reference or an array
  122. reference of subroutine references.  These callbacks will be called in
  123. the order they are given and passed a hash containing the following keys:
  124.  
  125.  ( message => $log_message, level => $log_level )
  126.  
  127. The callbacks are expected to modify the message and then return a
  128. single scalar containing that modified message.  These callbacks will
  129. be called when either the C<log> or C<log_to> methods are called and
  130. will only be applied to a given message once.
  131.  
  132. =back
  133.  
  134. =item * log_message( message => $ )
  135.  
  136. Sends a message to the appropriate output.  Generally this shouldn't
  137. be called directly but should be called through the C<log()> method
  138. (in Log::Dispatch::Output).
  139.  
  140. =back
  141.  
  142. =head1 AUTHOR
  143.  
  144. Dave Rolsky, <autarch@urth.org>
  145.  
  146. =cut
  147.