1package Log::Dispatch::ApacheLog; 2{ 3 $Log::Dispatch::ApacheLog::VERSION = '2.34'; 4} 5 6use strict; 7use warnings; 8 9use Log::Dispatch::Output; 10 11use base qw( Log::Dispatch::Output ); 12 13use Params::Validate qw(validate); 14Params::Validate::validation_options( allow_extra => 1 ); 15 16BEGIN { 17 if ( $ENV{MOD_PERL} && $ENV{MOD_PERL} =~ /2\./ ) { 18 require Apache2::Log; 19 } 20 else { 21 require Apache::Log; 22 } 23} 24 25sub new { 26 my $proto = shift; 27 my $class = ref $proto || $proto; 28 29 my %p = validate( @_, { apache => { can => 'log' } } ); 30 31 my $self = bless {}, $class; 32 33 $self->_basic_init(%p); 34 $self->{apache_log} = $p{apache}->log; 35 36 return $self; 37} 38 39{ 40 my %methods = ( 41 emergency => 'emerg', 42 critical => 'crit', 43 warning => 'warn', 44 ); 45 46 sub log_message { 47 my $self = shift; 48 my %p = @_; 49 50 my $level = $self->_level_as_name( $p{level} ); 51 52 my $method = $methods{$level} || $level; 53 54 $self->{apache_log}->$method( $p{message} ); 55 } 56} 57 581; 59 60# ABSTRACT: Object for logging to Apache::Log objects 61 62__END__ 63 64=pod 65 66=head1 NAME 67 68Log::Dispatch::ApacheLog - Object for logging to Apache::Log objects 69 70=head1 VERSION 71 72version 2.34 73 74=head1 SYNOPSIS 75 76 use Log::Dispatch; 77 78 my $log = Log::Dispatch->new( 79 outputs => [ 80 [ 'ApacheLog', apache => $r ], 81 ], 82 ); 83 84 $log->emerg('Kaboom'); 85 86=head1 DESCRIPTION 87 88This module allows you to pass messages to Apache's log object, 89represented by the L<Apache::Log> class. 90 91=head1 CONSTRUCTOR 92 93The constructor takes the following parameters in addition to the standard 94parameters documented in L<Log::Dispatch::Output>: 95 96=over 4 97 98=item * apache ($) 99 100An object of either the L<Apache> or L<Apache::Server> classes. Required. 101 102=back 103 104=head1 AUTHOR 105 106Dave Rolsky <autarch@urth.org> 107 108=head1 COPYRIGHT AND LICENSE 109 110This software is Copyright (c) 2011 by Dave Rolsky. 111 112This is free software, licensed under: 113 114 The Artistic License 2.0 (GPL Compatible) 115 116=cut 117