line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
###########################################################################
|
2
|
|
|
|
|
|
|
#
|
3
|
|
|
|
|
|
|
# Fork.pm
|
4
|
|
|
|
|
|
|
#
|
5
|
|
|
|
|
|
|
# Copyright (C) 1999 Raphael Manfredi.
|
6
|
|
|
|
|
|
|
# Copyright (C) 2002-2017 Mark Rogaski, mrogaski@cpan.org;
|
7
|
|
|
|
|
|
|
# all rights reserved.
|
8
|
|
|
|
|
|
|
#
|
9
|
|
|
|
|
|
|
# See the README file included with the
|
10
|
|
|
|
|
|
|
# distribution for license information.
|
11
|
|
|
|
|
|
|
#
|
12
|
|
|
|
|
|
|
##########################################################################
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
package Log::Agent::Driver::Fork;
|
15
|
|
|
|
|
|
|
|
16
|
2
|
|
|
2
|
|
1512
|
use strict;
|
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
80
|
|
17
|
|
|
|
|
|
|
require Log::Agent::Driver;
|
18
|
|
|
|
|
|
|
|
19
|
2
|
|
|
2
|
|
11
|
use vars qw(@ISA);
|
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
1901
|
|
20
|
|
|
|
|
|
|
@ISA = qw(Log::Agent::Driver);
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
###########################################################################
|
23
|
|
|
|
|
|
|
#
|
24
|
|
|
|
|
|
|
# Public Methods
|
25
|
|
|
|
|
|
|
#
|
26
|
|
|
|
|
|
|
###########################################################################
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
#
|
29
|
|
|
|
|
|
|
# make
|
30
|
|
|
|
|
|
|
#
|
31
|
|
|
|
|
|
|
# constructor method
|
32
|
|
|
|
|
|
|
#
|
33
|
|
|
|
|
|
|
sub make {
|
34
|
2
|
|
|
2
|
1
|
5
|
my $class = shift;
|
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# initialize the dispatcher
|
37
|
2
|
|
|
|
|
5
|
my $self = {
|
38
|
|
|
|
|
|
|
drivers => []
|
39
|
|
|
|
|
|
|
};
|
40
|
2
|
|
|
|
|
4
|
bless $self, $class;
|
41
|
2
|
|
|
|
|
12
|
$self->_init('', 0);
|
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# test for 5.6
|
44
|
2
|
|
|
|
|
5
|
$^W = 0;
|
45
|
2
|
|
50
|
|
|
150
|
my $new_perl = eval "$^V and $^V ge v5.6.0" || 0;
|
46
|
2
|
|
|
|
|
8
|
$^W = 1;
|
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
# process the arguments
|
49
|
2
|
|
|
|
|
6
|
foreach my $arg (@_) {
|
50
|
3
|
50
|
|
|
|
10
|
if (ref $arg) {
|
51
|
|
|
|
|
|
|
# add to the list of drivers
|
52
|
3
|
|
|
|
|
7
|
push(@{$self->{drivers}}, $arg);
|
|
3
|
|
|
|
|
9
|
|
53
|
|
|
|
|
|
|
} else {
|
54
|
0
|
|
|
|
|
0
|
require Carp;
|
55
|
0
|
|
|
|
|
0
|
Carp::croak("argument is not an object reference: $arg");
|
56
|
|
|
|
|
|
|
}
|
57
|
|
|
|
|
|
|
}
|
58
|
|
|
|
|
|
|
|
59
|
2
|
|
|
|
|
7
|
return $self;
|
60
|
|
|
|
|
|
|
}
|
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
#
|
63
|
|
|
|
|
|
|
# prefix_msg
|
64
|
|
|
|
|
|
|
#
|
65
|
|
|
|
|
|
|
# does little of value
|
66
|
|
|
|
|
|
|
#
|
67
|
|
|
|
|
|
|
sub prefix_msg {
|
68
|
0
|
|
|
0
|
1
|
0
|
return $_[1];
|
69
|
|
|
|
|
|
|
}
|
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
#
|
72
|
|
|
|
|
|
|
# write
|
73
|
|
|
|
|
|
|
#
|
74
|
|
|
|
|
|
|
# pass-through to drivers
|
75
|
|
|
|
|
|
|
#
|
76
|
|
|
|
|
|
|
sub write {
|
77
|
0
|
|
|
0
|
1
|
0
|
my($self, $channel, $priority, $str) = @_;
|
78
|
0
|
|
|
|
|
0
|
foreach my $driver (@{$self->{drivers}}) {
|
|
0
|
|
|
|
|
0
|
|
79
|
0
|
|
|
|
|
0
|
$driver->write($channel, $priority, $str);
|
80
|
|
|
|
|
|
|
}
|
81
|
|
|
|
|
|
|
}
|
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
#
|
84
|
|
|
|
|
|
|
# emit
|
85
|
|
|
|
|
|
|
#
|
86
|
|
|
|
|
|
|
# wrapper for write() that uses dynamically bound priority() and prefix_msg()
|
87
|
|
|
|
|
|
|
# methods
|
88
|
|
|
|
|
|
|
#
|
89
|
|
|
|
|
|
|
sub emit {
|
90
|
4
|
|
|
4
|
1
|
12
|
my($self, $channel, $priority, $str) = @_;
|
91
|
4
|
|
|
|
|
4
|
foreach my $driver (@{$self->{drivers}}) {
|
|
4
|
|
|
|
|
11
|
|
92
|
8
|
|
|
|
|
30
|
$driver->emit($channel, $priority, $str);
|
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
# This is a kludge to make duperr work in file driver,
|
95
|
|
|
|
|
|
|
# the encapsulation purists should lynch me for this.
|
96
|
8
|
100
|
|
|
|
59
|
if ($driver->isa('Log::Agent::Driver::File')) {
|
97
|
4
|
50
|
|
|
|
19
|
if ($driver->duperr) {
|
98
|
4
|
100
|
|
|
|
20
|
if ($priority eq 'critical') {
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
99
|
1
|
|
|
|
|
5
|
$driver->emit_output('critical', 'FATAL', $str);
|
100
|
|
|
|
|
|
|
} elsif ($priority eq 'error') {
|
101
|
1
|
|
|
|
|
4
|
$driver->emit_output('error', 'ERROR', $str);
|
102
|
|
|
|
|
|
|
} elsif ($priority eq 'warning') {
|
103
|
1
|
|
|
|
|
4
|
$driver->emit_output('warning', 'WARNING', $str);
|
104
|
|
|
|
|
|
|
}
|
105
|
|
|
|
|
|
|
}
|
106
|
|
|
|
|
|
|
}
|
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
}
|
109
|
|
|
|
|
|
|
}
|
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
#
|
112
|
|
|
|
|
|
|
# emit_carp
|
113
|
|
|
|
|
|
|
#
|
114
|
|
|
|
|
|
|
# A specialized wrapper to hand-off carp/croak messages at a
|
115
|
|
|
|
|
|
|
# specified offset.
|
116
|
|
|
|
|
|
|
#
|
117
|
|
|
|
|
|
|
sub emit_carp {
|
118
|
11
|
|
|
11
|
0
|
22
|
my($self, $channel, $priority, $offset, $str) = @_;
|
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
# yet another kludge
|
121
|
11
|
100
|
|
|
|
85
|
$offset++ if (caller(3))[3] =~ /^main::/;
|
122
|
|
|
|
|
|
|
|
123
|
11
|
|
|
|
|
23
|
foreach my $driver (@{$self->{drivers}}) {
|
|
11
|
|
|
|
|
30
|
|
124
|
|
|
|
|
|
|
# construct the message
|
125
|
11
|
|
|
|
|
62
|
require Carp;
|
126
|
11
|
|
|
|
|
44
|
my $msg = $driver->carpmess($offset, $str, \&Carp::shortmess);
|
127
|
|
|
|
|
|
|
# send it to the driver
|
128
|
11
|
|
|
|
|
32
|
$driver->emit($channel, $priority, $str);
|
129
|
|
|
|
|
|
|
}
|
130
|
|
|
|
|
|
|
}
|
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
#
|
133
|
|
|
|
|
|
|
# channel_eq
|
134
|
|
|
|
|
|
|
#
|
135
|
|
|
|
|
|
|
# exhaustive equality comparison
|
136
|
|
|
|
|
|
|
#
|
137
|
|
|
|
|
|
|
sub channel_eq {
|
138
|
0
|
|
|
0
|
1
|
0
|
my $self = shift;
|
139
|
0
|
|
|
|
|
0
|
foreach my $driver (@{$self->{drivers}}) {
|
|
0
|
|
|
|
|
0
|
|
140
|
0
|
0
|
|
|
|
0
|
$driver->channel_eq(@_) || return;
|
141
|
|
|
|
|
|
|
}
|
142
|
0
|
|
|
|
|
0
|
return 1;
|
143
|
|
|
|
|
|
|
}
|
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
#
|
146
|
|
|
|
|
|
|
# logconfess
|
147
|
|
|
|
|
|
|
#
|
148
|
|
|
|
|
|
|
# Fatal error, with stack trace
|
149
|
|
|
|
|
|
|
#
|
150
|
|
|
|
|
|
|
sub logconfess {
|
151
|
0
|
|
|
0
|
1
|
0
|
my($self, $str) = @_;
|
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
# log error to all drivers
|
154
|
0
|
|
|
|
|
0
|
$self->emit_carp('error', 'critical', 0, $str);
|
155
|
|
|
|
|
|
|
|
156
|
0
|
|
|
|
|
0
|
die;
|
157
|
|
|
|
|
|
|
}
|
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
#
|
160
|
|
|
|
|
|
|
# logcroak
|
161
|
|
|
|
|
|
|
#
|
162
|
|
|
|
|
|
|
# Fatal error
|
163
|
|
|
|
|
|
|
#
|
164
|
|
|
|
|
|
|
sub logcroak {
|
165
|
0
|
|
|
0
|
0
|
0
|
my($self, $str) = @_;
|
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
#
|
168
|
|
|
|
|
|
|
# log error to all drivers
|
169
|
|
|
|
|
|
|
#
|
170
|
0
|
|
|
|
|
0
|
$self->emit_carp('error', 'critical', 0, $str);
|
171
|
|
|
|
|
|
|
|
172
|
0
|
|
|
|
|
0
|
die;
|
173
|
|
|
|
|
|
|
}
|
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
#
|
176
|
|
|
|
|
|
|
# logxcroak
|
177
|
|
|
|
|
|
|
#
|
178
|
|
|
|
|
|
|
# Fatal error, from perspective of caller
|
179
|
|
|
|
|
|
|
#
|
180
|
|
|
|
|
|
|
sub logxcroak {
|
181
|
0
|
|
|
0
|
1
|
0
|
my($self, $offset, $str) = @_;
|
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
#
|
184
|
|
|
|
|
|
|
# log error to all drivers
|
185
|
|
|
|
|
|
|
#
|
186
|
0
|
|
|
|
|
0
|
$self->emit_carp('error', 'critical', $offset, $str);
|
187
|
|
|
|
|
|
|
|
188
|
0
|
|
|
|
|
0
|
die;
|
189
|
|
|
|
|
|
|
}
|
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
#
|
192
|
|
|
|
|
|
|
# logdie
|
193
|
|
|
|
|
|
|
#
|
194
|
|
|
|
|
|
|
# Fatal error
|
195
|
|
|
|
|
|
|
#
|
196
|
|
|
|
|
|
|
sub logdie {
|
197
|
1
|
|
|
1
|
1
|
3
|
my ($self, $str) = @_;
|
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
#
|
200
|
|
|
|
|
|
|
# log error to all drivers
|
201
|
|
|
|
|
|
|
#
|
202
|
1
|
|
|
|
|
4
|
$self->emit('error', 'critical', $str);
|
203
|
1
|
|
|
|
|
14
|
die;
|
204
|
|
|
|
|
|
|
}
|
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
#
|
207
|
|
|
|
|
|
|
# logerr
|
208
|
|
|
|
|
|
|
#
|
209
|
|
|
|
|
|
|
# Signal error on stderr
|
210
|
|
|
|
|
|
|
#
|
211
|
|
|
|
|
|
|
sub logerr {
|
212
|
1
|
|
|
1
|
1
|
3
|
my ($self, $str) = @_;
|
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
#
|
215
|
|
|
|
|
|
|
# log error to all drivers
|
216
|
|
|
|
|
|
|
#
|
217
|
1
|
|
|
|
|
4
|
$self->emit('error', 'error', $str);
|
218
|
|
|
|
|
|
|
}
|
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
#
|
221
|
|
|
|
|
|
|
# logwarn
|
222
|
|
|
|
|
|
|
#
|
223
|
|
|
|
|
|
|
# Warn, with "WARNING" clearly emphasized
|
224
|
|
|
|
|
|
|
#
|
225
|
|
|
|
|
|
|
sub logwarn {
|
226
|
1
|
|
|
1
|
1
|
3
|
my ($self, $str) = @_;
|
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
#
|
229
|
|
|
|
|
|
|
# log error to all drivers
|
230
|
|
|
|
|
|
|
#
|
231
|
1
|
|
|
|
|
4
|
$self->emit('error', 'warning', $str);
|
232
|
|
|
|
|
|
|
}
|
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
#
|
235
|
|
|
|
|
|
|
# logcarp
|
236
|
|
|
|
|
|
|
#
|
237
|
|
|
|
|
|
|
# log a warning, carp-style
|
238
|
|
|
|
|
|
|
#
|
239
|
|
|
|
|
|
|
sub logcarp {
|
240
|
0
|
|
|
0
|
0
|
0
|
my($self, $str) = @_;
|
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
#
|
243
|
|
|
|
|
|
|
# log message to all drivers
|
244
|
|
|
|
|
|
|
#
|
245
|
0
|
|
|
|
|
0
|
$self->emit_carp('error', 'warning', 0, $str);
|
246
|
|
|
|
|
|
|
}
|
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
#
|
249
|
|
|
|
|
|
|
# logxcarp
|
250
|
|
|
|
|
|
|
#
|
251
|
|
|
|
|
|
|
# Warn from perspective of caller
|
252
|
|
|
|
|
|
|
#
|
253
|
|
|
|
|
|
|
sub logxcarp {
|
254
|
11
|
|
|
11
|
1
|
24
|
my($self, $offset, $str) = @_;
|
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
#
|
257
|
|
|
|
|
|
|
# log message to all drivers
|
258
|
|
|
|
|
|
|
#
|
259
|
11
|
|
|
|
|
27
|
$self->emit_carp('error', 'warning', $offset, $str);
|
260
|
|
|
|
|
|
|
}
|
261
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
#
|
263
|
|
|
|
|
|
|
# logsay
|
264
|
|
|
|
|
|
|
#
|
265
|
|
|
|
|
|
|
# Log message to "output" channel at "notice" priority
|
266
|
|
|
|
|
|
|
#
|
267
|
|
|
|
|
|
|
sub logsay {
|
268
|
1
|
|
|
1
|
1
|
3
|
my($self, $str) = @_;
|
269
|
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
#
|
271
|
|
|
|
|
|
|
# send message to drivers
|
272
|
|
|
|
|
|
|
#
|
273
|
1
|
|
|
|
|
36
|
$self->emit('output', 'notice', $str);
|
274
|
|
|
|
|
|
|
}
|
275
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
1; # for require
|
277
|
|
|
|
|
|
|
__END__
|