line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Log::Agent::Driver::Apache; |
2
|
1
|
|
|
1
|
|
959
|
use 5.008006; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
44
|
|
3
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
29
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
34
|
|
5
|
1
|
|
|
1
|
|
18477
|
use Apache2::Log; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
use Apache2::ServerUtil; |
7
|
|
|
|
|
|
|
use Log::Agent::Driver; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our(@ISA) = qw(Log::Agent::Driver); |
10
|
|
|
|
|
|
|
our($VERSION) = 0.002; |
11
|
|
|
|
|
|
|
use vars qw(%PRI_MAP); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
# |
14
|
|
|
|
|
|
|
# %PRI_MAP is a mapping of priorities to underlying Apache2::Log->log()->$method |
15
|
|
|
|
|
|
|
# |
16
|
|
|
|
|
|
|
# priority => method. Others, not listed, are info and debug. |
17
|
|
|
|
|
|
|
%PRI_MAP = ( |
18
|
|
|
|
|
|
|
emergency => 'emerg', |
19
|
|
|
|
|
|
|
alert => 'alert', |
20
|
|
|
|
|
|
|
critical => 'crit', |
21
|
|
|
|
|
|
|
error => 'error', |
22
|
|
|
|
|
|
|
warning => 'warn', |
23
|
|
|
|
|
|
|
notice => 'notice' |
24
|
|
|
|
|
|
|
); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# this is the constructor. |
27
|
|
|
|
|
|
|
sub make { |
28
|
|
|
|
|
|
|
my($this) = shift; |
29
|
|
|
|
|
|
|
my(%opt) = @_; |
30
|
|
|
|
|
|
|
$this = ref($this) || $this; |
31
|
|
|
|
|
|
|
my($self) = bless({},$this); |
32
|
|
|
|
|
|
|
$self->{'_apache_log'} = $opt{'-log'} || _default_log(); |
33
|
|
|
|
|
|
|
return($self); |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# By default, we use server log. |
37
|
|
|
|
|
|
|
sub _default_log { |
38
|
|
|
|
|
|
|
my $s = Apache2::ServerUtil->server(); |
39
|
|
|
|
|
|
|
return($s->log); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
sub channel_eq { |
42
|
|
|
|
|
|
|
my($self,$ch1,$ch2) = (shift,shift,shift); |
43
|
|
|
|
|
|
|
return(1); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub write { |
47
|
|
|
|
|
|
|
my($self,$channel,$priority,$logstring) = @_; |
48
|
|
|
|
|
|
|
my($l) = $self->{_apache_log} || 0; |
49
|
|
|
|
|
|
|
# Attempt to log something without logging anything? |
50
|
|
|
|
|
|
|
$logstring ||= join(",",caller()) . " (something was logged)"; |
51
|
|
|
|
|
|
|
if(! $l){ |
52
|
|
|
|
|
|
|
# Since the message may have something to do |
53
|
|
|
|
|
|
|
# with Apache::Log itself, or, misconfiguration |
54
|
|
|
|
|
|
|
# or the other things that can go wrong.. we issue |
55
|
|
|
|
|
|
|
# a warn here. |
56
|
|
|
|
|
|
|
warn "(log config. prob) $priority $logstring"; |
57
|
|
|
|
|
|
|
return; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
if($channel eq 'debug'){ |
60
|
|
|
|
|
|
|
$l->debug($logstring); |
61
|
|
|
|
|
|
|
return(); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
$priority ||= 0; |
64
|
|
|
|
|
|
|
my($meth); |
65
|
|
|
|
|
|
|
if($l->can($priority)){ |
66
|
|
|
|
|
|
|
$meth = $priority; |
67
|
|
|
|
|
|
|
}else{ |
68
|
|
|
|
|
|
|
$meth = 'info'; # A reasonable default? |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
eval { |
71
|
|
|
|
|
|
|
$l->$meth($logstring); |
72
|
|
|
|
|
|
|
}; |
73
|
|
|
|
|
|
|
if($@){ |
74
|
|
|
|
|
|
|
warn "$@ $logstring"; # Couldn't log for some reason? |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
return(); |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
# Map priorities to methods. |
79
|
|
|
|
|
|
|
sub map_pri { |
80
|
|
|
|
|
|
|
my ($self,$priority, $level) = (shift,shift,shift); |
81
|
|
|
|
|
|
|
my($l) = $self->{_apache_log} || 0; |
82
|
|
|
|
|
|
|
if($l){ |
83
|
|
|
|
|
|
|
if($l->can($priority)){ |
84
|
|
|
|
|
|
|
return($priority); |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
return($PRI_MAP{$priority}); |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub prefix_msg { |
91
|
|
|
|
|
|
|
shift; # self, |
92
|
|
|
|
|
|
|
return(shift()); # Whatever the message is. |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
1; |
96
|
|
|
|
|
|
|
__END__ |