| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Log::Dispatch::Perl; |
|
2
|
1
|
|
|
1
|
|
1139
|
use base 'Log::Dispatch::Output'; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
1744
|
|
|
3
|
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
$VERSION= '0.04'; |
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
# be as strict and verbose as possible |
|
7
|
1
|
|
|
1
|
|
20082
|
use strict; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
32
|
|
|
8
|
1
|
|
|
1
|
|
16
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
1075
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
# initialize level name / number conversion hashes |
|
11
|
|
|
|
|
|
|
my %LEVEL2NUM; |
|
12
|
|
|
|
|
|
|
my %NUM2LEVEL; |
|
13
|
|
|
|
|
|
|
do { |
|
14
|
|
|
|
|
|
|
my @level2num= ( |
|
15
|
|
|
|
|
|
|
debug => 0, |
|
16
|
|
|
|
|
|
|
info => 1, |
|
17
|
|
|
|
|
|
|
notice => 2, |
|
18
|
|
|
|
|
|
|
warning => 3, |
|
19
|
|
|
|
|
|
|
error => 4, |
|
20
|
|
|
|
|
|
|
err => 4, # MUST be after "error" |
|
21
|
|
|
|
|
|
|
critical => 5, |
|
22
|
|
|
|
|
|
|
crit => 5, # MUST be after "critical" |
|
23
|
|
|
|
|
|
|
alert => 6, |
|
24
|
|
|
|
|
|
|
emergency => 7, |
|
25
|
|
|
|
|
|
|
emerg => 7, # MUST be after "emergency" |
|
26
|
|
|
|
|
|
|
); |
|
27
|
|
|
|
|
|
|
%LEVEL2NUM= @level2num; |
|
28
|
|
|
|
|
|
|
%NUM2LEVEL= reverse @level2num; # order fixes double assignments |
|
29
|
|
|
|
|
|
|
}; |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# hide ourselves from Carp |
|
32
|
|
|
|
|
|
|
my $havecarp= defined $Carp::VERSION; |
|
33
|
|
|
|
|
|
|
unless ( $] < 5.008 ) { |
|
34
|
|
|
|
|
|
|
$Carp::Internal{$_}= 1 foreach ( 'Log::Dispatch', 'Log::Dispatch::Output' ); |
|
35
|
|
|
|
|
|
|
} |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
# action to actual code hash |
|
38
|
|
|
|
|
|
|
my %ACTION2CODE; |
|
39
|
|
|
|
|
|
|
%ACTION2CODE= ( |
|
40
|
|
|
|
|
|
|
'' => sub { undef }, |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
carp => $havecarp |
|
43
|
|
|
|
|
|
|
? \&Carp::carp |
|
44
|
|
|
|
|
|
|
: sub { |
|
45
|
|
|
|
|
|
|
$havecarp ||= require Carp; |
|
46
|
|
|
|
|
|
|
$ACTION2CODE{carp}= \&Carp::carp; |
|
47
|
|
|
|
|
|
|
goto &Carp::carp; |
|
48
|
|
|
|
|
|
|
}, |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
cluck => $] < 5.008 |
|
51
|
|
|
|
|
|
|
? sub { |
|
52
|
|
|
|
|
|
|
$havecarp ||= require Carp; |
|
53
|
|
|
|
|
|
|
( my $m= Carp::longmess() ) |
|
54
|
|
|
|
|
|
|
=~ s#\s+Log::Dispatch::[^\n]+\n##sg; |
|
55
|
|
|
|
|
|
|
return CORE::warn $_[0] . $m; |
|
56
|
|
|
|
|
|
|
} |
|
57
|
|
|
|
|
|
|
: sub { |
|
58
|
|
|
|
|
|
|
$havecarp ||= require Carp; |
|
59
|
|
|
|
|
|
|
return CORE::warn $_[0] . Carp::longmess(); |
|
60
|
|
|
|
|
|
|
}, |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
confess => $] < 5.008 |
|
63
|
|
|
|
|
|
|
? sub { |
|
64
|
|
|
|
|
|
|
$havecarp ||= require Carp; |
|
65
|
|
|
|
|
|
|
( my $m = Carp::longmess() ) |
|
66
|
|
|
|
|
|
|
=~ s#\s+Log::Dispatch::[^\n]+\n##sg; |
|
67
|
|
|
|
|
|
|
return CORE::die $_[0] . $m; |
|
68
|
|
|
|
|
|
|
} |
|
69
|
|
|
|
|
|
|
: sub { |
|
70
|
|
|
|
|
|
|
$havecarp ||= require Carp; |
|
71
|
|
|
|
|
|
|
return CORE::die $_[0] . Carp::longmess(); |
|
72
|
|
|
|
|
|
|
}, |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
croak => $havecarp |
|
75
|
|
|
|
|
|
|
? \&Carp::croak |
|
76
|
|
|
|
|
|
|
: sub { |
|
77
|
|
|
|
|
|
|
$havecarp ||= require Carp; |
|
78
|
|
|
|
|
|
|
$ACTION2CODE{croak}= \&Carp::croak; |
|
79
|
|
|
|
|
|
|
goto &Carp::croak; |
|
80
|
|
|
|
|
|
|
}, |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
die => sub { CORE::die @_ }, |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
warn => sub { CORE::warn @_ }, |
|
85
|
|
|
|
|
|
|
); |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
# satisfy require |
|
88
|
|
|
|
|
|
|
1; |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
|
91
|
|
|
|
|
|
|
# |
|
92
|
|
|
|
|
|
|
# Class methods |
|
93
|
|
|
|
|
|
|
# |
|
94
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
|
95
|
|
|
|
|
|
|
# new |
|
96
|
|
|
|
|
|
|
# |
|
97
|
|
|
|
|
|
|
# Required by Log::Dispatch::Output. Creates a new Log::Dispatch::Perl |
|
98
|
|
|
|
|
|
|
# object |
|
99
|
|
|
|
|
|
|
# |
|
100
|
|
|
|
|
|
|
# IN: 1 class |
|
101
|
|
|
|
|
|
|
# 2..N parameters as a hash |
|
102
|
|
|
|
|
|
|
# OUT: 1 instantiated object |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub new { |
|
105
|
1
|
|
|
1
|
0
|
2184
|
my ( $class, %param )= @_; |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
# do the basic initializations |
|
108
|
1
|
|
33
|
|
|
11
|
my $self= bless {}, ref $class || $class; |
|
109
|
1
|
|
|
|
|
9
|
$self->_basic_init( %param ); |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
# we have specific actions specified |
|
112
|
1
|
|
|
|
|
126
|
my @action; |
|
113
|
1
|
50
|
|
|
|
4
|
if ( my $actions= $param{action} ) { |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
# check all actions specified |
|
116
|
0
|
|
|
|
|
0
|
foreach my $level ( keys %{$actions} ) { |
|
|
0
|
|
|
|
|
0
|
|
|
117
|
0
|
|
|
|
|
0
|
my $action= $actions->{$level}; |
|
118
|
0
|
0
|
|
|
|
0
|
$level= $NUM2LEVEL{$level} if exists $NUM2LEVEL{$level}; |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
# sanity check, store if ok |
|
121
|
0
|
|
|
|
|
0
|
my $warn; |
|
122
|
0
|
0
|
0
|
|
|
0
|
warn qq{"$level" is an unknown logging level, ignored\n"}, $warn++ |
|
123
|
|
|
|
|
|
|
if !exists $LEVEL2NUM{ $level || '' }; |
|
124
|
0
|
0
|
|
|
|
0
|
warn qq{"$action" is an unknown Perl action, ignored\n"}, $warn++ |
|
125
|
|
|
|
|
|
|
if !exists $ACTION2CODE{$action}; |
|
126
|
0
|
0
|
|
|
|
0
|
$action[$LEVEL2NUM{$level}]= $ACTION2CODE{$action} |
|
127
|
|
|
|
|
|
|
if !$warn; |
|
128
|
|
|
|
|
|
|
} |
|
129
|
|
|
|
|
|
|
} |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
# set the actions that have not yet been specified |
|
132
|
1
|
|
33
|
|
|
6
|
$action[0] ||= $ACTION2CODE{''}; |
|
133
|
1
|
|
33
|
|
|
6
|
$action[1] ||= $ACTION2CODE{''}; |
|
134
|
1
|
|
33
|
|
|
5
|
$action[2] ||= $ACTION2CODE{warn}; |
|
135
|
1
|
|
33
|
|
|
5
|
$action[3] ||= $ACTION2CODE{warn}; |
|
136
|
1
|
|
33
|
|
|
8
|
$action[4] ||= $ACTION2CODE{die}; |
|
137
|
1
|
|
33
|
|
|
6
|
$action[5] ||= $ACTION2CODE{die}; |
|
138
|
1
|
|
33
|
|
|
5
|
$action[6] ||= $ACTION2CODE{confess}; |
|
139
|
1
|
|
33
|
|
|
5
|
$action[7] ||= $ACTION2CODE{confess}; |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
# save this setting |
|
142
|
1
|
|
|
|
|
3
|
$self->{action}= \@action; |
|
143
|
|
|
|
|
|
|
|
|
144
|
1
|
|
|
|
|
4
|
return $self; |
|
145
|
|
|
|
|
|
|
} #new |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
|
148
|
|
|
|
|
|
|
# |
|
149
|
|
|
|
|
|
|
# Instance methods |
|
150
|
|
|
|
|
|
|
# |
|
151
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
|
152
|
|
|
|
|
|
|
# log_message |
|
153
|
|
|
|
|
|
|
# |
|
154
|
|
|
|
|
|
|
# Required by Log::Dispatch. Log a single message. |
|
155
|
|
|
|
|
|
|
# |
|
156
|
|
|
|
|
|
|
# IN: 1 instantiated Log::Dispatch::Perl object |
|
157
|
|
|
|
|
|
|
# 2..N hash with parameters as required by Log::Dispatch |
|
158
|
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
sub log_message { |
|
160
|
8
|
|
|
8
|
0
|
26784
|
my ( $self, %param )= @_; |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
# huh? |
|
163
|
8
|
|
|
|
|
18
|
my $level= $param{level}; |
|
164
|
8
|
0
|
33
|
|
|
27
|
return if !exists $LEVEL2NUM{$level} and !exists $NUM2LEVEL{$level}; |
|
165
|
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
# obtain level number |
|
167
|
8
|
|
|
|
|
14
|
my $num= $LEVEL2NUM{$level}; |
|
168
|
8
|
50
|
|
|
|
18
|
$num= $level if !defined $num; # //= |
|
169
|
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
# set message |
|
171
|
8
|
|
|
|
|
12
|
my $message= $param{message}; |
|
172
|
8
|
50
|
|
|
|
35
|
$message .= "\n" if substr( $message, -1, 1 ) ne "\n"; |
|
173
|
8
|
|
|
|
|
21
|
@_= ($message); |
|
174
|
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
# log it the right way |
|
176
|
8
|
|
|
|
|
11
|
goto &{$self->{action}->[$num]}; |
|
|
8
|
|
|
|
|
45
|
|
|
177
|
|
|
|
|
|
|
} #log_message |
|
178
|
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
|
180
|
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
__END__ |