Skip to content

Commit c038d2c

Browse files
committed
[#132 state:committed] Adding Log::Log4perl and Log::Dispatch for new logging subsystem development
1 parent 9aac1a1 commit c038d2c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+19149
-0
lines changed

extlib/Log/Dispatch.pm

Lines changed: 523 additions & 0 deletions
Large diffs are not rendered by default.

extlib/Log/Dispatch/ApacheLog.pm

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

extlib/Log/Dispatch/Base.pm

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package Log::Dispatch::Base;
2+
3+
use strict;
4+
use warnings;
5+
6+
our $VERSION = '1.09';
7+
8+
9+
sub _get_callbacks
10+
{
11+
shift;
12+
my %p = @_;
13+
14+
return unless exists $p{callbacks};
15+
16+
return @{ $p{callbacks} }
17+
if UNIVERSAL::isa( $p{callbacks}, 'ARRAY' );
18+
19+
return $p{callbacks}
20+
if UNIVERSAL::isa( $p{callbacks}, 'CODE' );
21+
22+
return;
23+
}
24+
25+
sub _apply_callbacks
26+
{
27+
my $self = shift;
28+
my %p = @_;
29+
30+
my $msg = delete $p{message};
31+
foreach my $cb ( @{ $self->{callbacks} } )
32+
{
33+
$msg = $cb->( message => $msg, %p );
34+
}
35+
36+
return $msg;
37+
}
38+
39+
40+
1;
41+
42+
__END__
43+
44+
=head1 NAME
45+
46+
Log::Dispatch::Base - Code shared by dispatch and output objects.
47+
48+
=head1 SYNOPSIS
49+
50+
use Log::Dispatch::Base;
51+
52+
...
53+
54+
@ISA = qw(Log::Dispatch::Base);
55+
56+
=head1 DESCRIPTION
57+
58+
Unless you are me, you probably don't need to know what this class
59+
does.
60+
61+
=head1 AUTHOR
62+
63+
Dave Rolsky, <autarch@urth.org>
64+
65+
=cut

0 commit comments

Comments
 (0)