line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#line 1 |
2
|
|
|
|
|
|
|
package Log::Dispatch; |
3
|
2
|
|
|
2
|
|
1537
|
|
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
71
|
|
4
|
|
|
|
|
|
|
use 5.006; |
5
|
2
|
|
|
2
|
|
10
|
|
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
86
|
|
6
|
2
|
|
|
2
|
|
10
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
193
|
|
7
|
|
|
|
|
|
|
use warnings; |
8
|
2
|
|
|
2
|
|
16
|
|
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
1805
|
|
9
|
|
|
|
|
|
|
use base qw( Log::Dispatch::Base ); |
10
|
2
|
|
|
2
|
|
748
|
|
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
246
|
|
11
|
|
|
|
|
|
|
use Carp (); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our $VERSION = '2.22'; |
14
|
|
|
|
|
|
|
our %LEVELS; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
BEGIN |
18
|
2
|
|
|
2
|
|
6
|
{ |
19
|
|
|
|
|
|
|
foreach my $l ( qw( debug info notice warning err error crit critical alert emerg emergency ) ) |
20
|
0
|
|
|
|
|
0
|
{ |
21
|
22
|
|
|
|
|
94
|
my $sub = sub { my $self = shift; |
|
0
|
|
|
|
|
0
|
|
22
|
|
|
|
|
|
|
$self->log( level => $l, message => "@_" ); }; |
23
|
22
|
|
|
|
|
60
|
|
24
|
|
|
|
|
|
|
$LEVELS{$l} = 1; |
25
|
2
|
|
|
2
|
|
10
|
|
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
63
|
|
26
|
22
|
|
|
|
|
17
|
no strict 'refs'; |
|
22
|
|
|
|
|
2073
|
|
27
|
|
|
|
|
|
|
*{$l} = $sub |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub new |
32
|
1
|
|
|
1
|
1
|
12
|
{ |
33
|
1
|
|
33
|
|
|
9
|
my $proto = shift; |
34
|
1
|
|
|
|
|
4
|
my $class = ref $proto || $proto; |
35
|
|
|
|
|
|
|
my %p = @_; |
36
|
1
|
|
|
|
|
3
|
|
37
|
|
|
|
|
|
|
my $self = bless {}, $class; |
38
|
1
|
|
|
|
|
16
|
|
39
|
1
|
50
|
|
|
|
11
|
my @cb = $self->_get_callbacks(%p); |
40
|
|
|
|
|
|
|
$self->{callbacks} = \@cb if @cb; |
41
|
1
|
|
|
|
|
4
|
|
42
|
|
|
|
|
|
|
return $self; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub add |
46
|
1
|
|
|
1
|
1
|
7
|
{ |
47
|
1
|
|
|
|
|
2
|
my $self = shift; |
48
|
|
|
|
|
|
|
my $object = shift; |
49
|
|
|
|
|
|
|
|
50
|
1
|
0
|
33
|
|
|
14
|
# Once 5.6 is more established start using the warnings module. |
51
|
|
|
|
|
|
|
if (exists $self->{outputs}{$object->name} && $^W) |
52
|
0
|
|
|
|
|
0
|
{ |
53
|
|
|
|
|
|
|
Carp::carp("Log::Dispatch::* object ", $object->name, " already exists."); |
54
|
|
|
|
|
|
|
} |
55
|
1
|
|
|
|
|
13
|
|
56
|
|
|
|
|
|
|
$self->{outputs}{$object->name} = $object; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub remove |
60
|
0
|
|
|
0
|
1
|
0
|
{ |
61
|
0
|
|
|
|
|
0
|
my $self = shift; |
62
|
|
|
|
|
|
|
my $name = shift; |
63
|
0
|
|
|
|
|
0
|
|
64
|
|
|
|
|
|
|
return delete $self->{outputs}{$name}; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub log |
68
|
2
|
|
|
2
|
1
|
4
|
{ |
69
|
2
|
|
|
|
|
10
|
my $self = shift; |
70
|
|
|
|
|
|
|
my %p = @_; |
71
|
2
|
50
|
|
|
|
7
|
|
72
|
|
|
|
|
|
|
return unless $self->would_log( $p{level} ); |
73
|
2
|
|
|
|
|
31
|
|
74
|
|
|
|
|
|
|
$self->_log_to_outputs( $self->_prepare_message(%p) ); |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub _prepare_message |
78
|
2
|
|
|
2
|
|
4
|
{ |
79
|
2
|
|
|
|
|
13
|
my $self = shift; |
80
|
|
|
|
|
|
|
my %p = @_; |
81
|
2
|
50
|
|
|
|
9
|
|
82
|
|
|
|
|
|
|
$p{message} = $p{message}->() |
83
|
|
|
|
|
|
|
if ref $p{message} eq 'CODE'; |
84
|
2
|
50
|
|
|
|
6
|
|
85
|
|
|
|
|
|
|
$p{message} = $self->_apply_callbacks(%p) |
86
|
|
|
|
|
|
|
if $self->{callbacks}; |
87
|
2
|
|
|
|
|
14
|
|
88
|
|
|
|
|
|
|
return %p; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub _log_to_outputs |
92
|
2
|
|
|
2
|
|
5
|
{ |
93
|
2
|
|
|
|
|
6
|
my $self = shift; |
94
|
|
|
|
|
|
|
my %p = @_; |
95
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
9
|
|
96
|
|
|
|
|
|
|
foreach (keys %{ $self->{outputs} }) |
97
|
2
|
|
|
|
|
5
|
{ |
98
|
2
|
|
|
|
|
10
|
$p{name} = $_; |
99
|
|
|
|
|
|
|
$self->_log_to(%p); |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub log_and_die |
104
|
0
|
|
|
0
|
1
|
0
|
{ |
105
|
|
|
|
|
|
|
my $self = shift; |
106
|
0
|
|
|
|
|
0
|
|
107
|
|
|
|
|
|
|
my %p = $self->_prepare_message(@_); |
108
|
0
|
0
|
|
|
|
0
|
|
109
|
|
|
|
|
|
|
$self->_log_to_outputs(%p) if $self->would_log($p{level}); |
110
|
0
|
|
|
|
|
0
|
|
111
|
|
|
|
|
|
|
$self->_die_with_message(%p); |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub log_and_croak |
115
|
0
|
|
|
0
|
1
|
0
|
{ |
116
|
|
|
|
|
|
|
my $self = shift; |
117
|
0
|
|
|
|
|
0
|
|
118
|
|
|
|
|
|
|
$self->log_and_die( @_, carp_level => 3 ); |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub _die_with_message |
122
|
0
|
|
|
0
|
|
0
|
{ |
123
|
0
|
|
|
|
|
0
|
my $self = shift; |
124
|
|
|
|
|
|
|
my %p = @_; |
125
|
0
|
|
|
|
|
0
|
|
126
|
|
|
|
|
|
|
my $msg = $p{message}; |
127
|
0
|
0
|
0
|
|
|
0
|
|
128
|
|
|
|
|
|
|
local $Carp::CarpLevel = ($Carp::CarpLevel || 0) + $p{carp_level} |
129
|
|
|
|
|
|
|
if exists $p{carp_level}; |
130
|
0
|
|
|
|
|
0
|
|
131
|
|
|
|
|
|
|
Carp::croak($msg); |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
sub log_to |
135
|
0
|
|
|
0
|
1
|
0
|
{ |
136
|
0
|
|
|
|
|
0
|
my $self = shift; |
137
|
|
|
|
|
|
|
my %p = @_; |
138
|
0
|
0
|
|
|
|
0
|
|
139
|
|
|
|
|
|
|
$p{message} = $self->_apply_callbacks(%p) |
140
|
|
|
|
|
|
|
if $self->{callbacks}; |
141
|
0
|
|
|
|
|
0
|
|
142
|
|
|
|
|
|
|
$self->_log_to(%p); |
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
sub _log_to |
146
|
2
|
|
|
2
|
|
4
|
{ |
147
|
2
|
|
|
|
|
6
|
my $self = shift; |
148
|
2
|
|
|
|
|
5
|
my %p = @_; |
149
|
|
|
|
|
|
|
my $name = $p{name}; |
150
|
2
|
50
|
|
|
|
15
|
|
|
|
0
|
|
|
|
|
|
151
|
|
|
|
|
|
|
if (exists $self->{outputs}{$name}) |
152
|
2
|
|
|
|
|
13
|
{ |
153
|
|
|
|
|
|
|
$self->{outputs}{$name}->log(@_); |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
elsif ($^W) |
156
|
0
|
|
|
|
|
0
|
{ |
157
|
|
|
|
|
|
|
Carp::carp("Log::Dispatch::* object named '$name' not in dispatcher\n"); |
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
} |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
sub output |
162
|
0
|
|
|
0
|
1
|
0
|
{ |
163
|
0
|
|
|
|
|
0
|
my $self = shift; |
164
|
|
|
|
|
|
|
my $name = shift; |
165
|
0
|
0
|
|
|
|
0
|
|
166
|
|
|
|
|
|
|
return unless exists $self->{outputs}{$name}; |
167
|
0
|
|
|
|
|
0
|
|
168
|
|
|
|
|
|
|
return $self->{outputs}{$name}; |
169
|
|
|
|
|
|
|
} |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
sub level_is_valid |
172
|
7
|
|
|
7
|
1
|
138
|
{ |
173
|
7
|
|
|
|
|
21
|
shift; |
174
|
|
|
|
|
|
|
return $LEVELS{ shift() }; |
175
|
|
|
|
|
|
|
} |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
sub would_log |
178
|
2
|
|
|
2
|
1
|
4
|
{ |
179
|
2
|
|
|
|
|
3
|
my $self = shift; |
180
|
|
|
|
|
|
|
my $level = shift; |
181
|
2
|
50
|
|
|
|
6
|
|
182
|
|
|
|
|
|
|
return 0 unless $self->level_is_valid($level); |
183
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
9
|
|
184
|
|
|
|
|
|
|
foreach ( values %{ $self->{outputs} } ) |
185
|
2
|
50
|
|
|
|
14
|
{ |
186
|
|
|
|
|
|
|
return 1 if $_->_should_log($level); |
187
|
|
|
|
|
|
|
} |
188
|
0
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
return 0; |
190
|
|
|
|
|
|
|
} |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
1; |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
__END__ |