| 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 | ▶ | use strict; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 17 | 2 | require Log::Agent::Driver; | |||||||||||||||||
| 18 | |||||||||||||||||||
| 19 | 2 | ▶ | use vars qw(@ISA); | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 20 | 2 | @ISA = qw(Log::Agent::Driver); | |||||||||||||||||
| 21 | |||||||||||||||||||
| 22 | ########################################################################### | ||||||||||||||||||
| 23 | # | ||||||||||||||||||
| 24 | # Public Methods | ||||||||||||||||||
| 25 | # | ||||||||||||||||||
| 26 | ########################################################################### | ||||||||||||||||||
| 27 | |||||||||||||||||||
| 28 | # | ||||||||||||||||||
| 29 | # make | ||||||||||||||||||
| 30 | # | ||||||||||||||||||
| 31 | # constructor method | ||||||||||||||||||
| 32 | # | ||||||||||||||||||
| 33 | 2 | ▶ | sub make { | ||||||||||||||||
|
Subroutine
make: called CC=4 SCAR=14.3
Pod
documented
| |||||||||||||||||||
| 34 | 2 | my $class = shift; | |||||||||||||||||
| 35 | |||||||||||||||||||
| 36 | # initialize the dispatcher | ||||||||||||||||||
| 37 | 2 | my $self = { | |||||||||||||||||
| 38 | drivers => [] | ||||||||||||||||||
| 39 | }; | ||||||||||||||||||
| 40 | 2 | bless $self, $class; | |||||||||||||||||
| 41 | 2 | $self->_init('', 0); | |||||||||||||||||
| 42 | |||||||||||||||||||
| 43 | # test for 5.6 | ||||||||||||||||||
| 44 | 2 | $^W = 0; | |||||||||||||||||
| 45 | 2 | ▶ | my $new_perl = eval "$^V and $^V ge v5.6.0" || 0; | ||||||||||||||||
|
Condition50%1/2
eval "$^V and $^V ge v5.6.0" || 0
MC/DC0%0/1
eval "$^V and $^V ge v5.6.0" || 0
eval "$^V and $^V ge v5.6.0"
Truth table50%1/2
A
A= eval "$^V and $^V ge v5.6.0"
| |||||||||||||||||||
| 46 | 2 | $^W = 1; | |||||||||||||||||
| 47 | |||||||||||||||||||
| 48 | # process the arguments | ||||||||||||||||||
| 49 | 2 | foreach my $arg (@_) { | |||||||||||||||||
| 50 | 3 | ▶ | if (ref $arg) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 51 | # add to the list of drivers | ||||||||||||||||||
| 52 | 3 | push(@{$self->{drivers}}, $arg); | |||||||||||||||||
| 53 | } else { | ||||||||||||||||||
| 54 | 0 | require Carp; | |||||||||||||||||
| 55 | 0 | Carp::croak("argument is not an object reference: $arg"); | |||||||||||||||||
| 56 | } | ||||||||||||||||||
| 57 | } | ||||||||||||||||||
| 58 | |||||||||||||||||||
| 59 | 2 | return $self; | |||||||||||||||||
| 60 | } | ||||||||||||||||||
| 61 | |||||||||||||||||||
| 62 | # | ||||||||||||||||||
| 63 | # prefix_msg | ||||||||||||||||||
| 64 | # | ||||||||||||||||||
| 65 | # does little of value | ||||||||||||||||||
| 66 | # | ||||||||||||||||||
| 67 | 1 | ▶ | sub prefix_msg { | ||||||||||||||||
|
Subroutine
prefix_msg: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||
| 68 | 1 | return $_[1]; | |||||||||||||||||
| 69 | } | ||||||||||||||||||
| 70 | |||||||||||||||||||
| 71 | # | ||||||||||||||||||
| 72 | # write | ||||||||||||||||||
| 73 | # | ||||||||||||||||||
| 74 | # pass-through to drivers | ||||||||||||||||||
| 75 | # | ||||||||||||||||||
| 76 | 1 | ▶ | sub write { | ||||||||||||||||
|
Subroutine
write: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||
| 77 | 1 | my($self, $channel, $priority, $str) = @_; | |||||||||||||||||
| 78 | 1 | foreach my $driver (@{$self->{drivers}}) { | |||||||||||||||||
| 79 | 2 | $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 | 6 | ▶ | sub emit { | ||||||||||||||||
|
Subroutine
emit: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||
| 90 | 6 | my($self, $channel, $priority, $str) = @_; | |||||||||||||||||
| 91 | 6 | foreach my $driver (@{$self->{drivers}}) { | |||||||||||||||||
| 92 | 12 | $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 | 12 | ▶ | if ($driver->isa('Log::Agent::Driver::File')) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 97 | 6 | ▶ | if ($driver->duperr) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 98 | 6 | ▶ | if ($priority eq 'critical') { | ||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||
| 99 | 1 | $driver->emit_output('critical', 'FATAL', $str); | |||||||||||||||||
| 100 | } elsif ($priority eq 'error') { | ||||||||||||||||||
| 101 | 1 | $driver->emit_output('error', 'ERROR', $str); | |||||||||||||||||
| 102 | } elsif ($priority eq 'warning') { | ||||||||||||||||||
| 103 | 1 | $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 | 11 | ▶ | sub emit_carp { | ||||||||||||||||
|
Subroutine
emit_carp: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||
| 118 | 11 | my($self, $channel, $priority, $offset, $str) = @_; | |||||||||||||||||
| 119 | |||||||||||||||||||
| 120 | # yet another kludge | ||||||||||||||||||
| 121 | 11 | ▶ | $offset++ if (caller(3))[3] =~ /^main::/; | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 122 | |||||||||||||||||||
| 123 | 11 | foreach my $driver (@{$self->{drivers}}) { | |||||||||||||||||
| 124 | # construct the message | ||||||||||||||||||
| 125 | 11 | require Carp; | |||||||||||||||||
| 126 | 11 | my $msg = $driver->carpmess($offset, $str, \&Carp::shortmess); | |||||||||||||||||
| 127 | # send it to the driver | ||||||||||||||||||
| 128 | 11 | $driver->emit($channel, $priority, $str); | |||||||||||||||||
| 129 | } | ||||||||||||||||||
| 130 | } | ||||||||||||||||||
| 131 | |||||||||||||||||||
| 132 | # | ||||||||||||||||||
| 133 | # channel_eq | ||||||||||||||||||
| 134 | # | ||||||||||||||||||
| 135 | # exhaustive equality comparison | ||||||||||||||||||
| 136 | # | ||||||||||||||||||
| 137 | 0 | ▶ | sub channel_eq { | ||||||||||||||||
|
Subroutine
channel_eq: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||
| 138 | 0 | my $self = shift; | |||||||||||||||||
| 139 | 0 | foreach my $driver (@{$self->{drivers}}) { | |||||||||||||||||
| 140 | 0 | ▶ | $driver->channel_eq(@_) || return; | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 141 | } | ||||||||||||||||||
| 142 | 0 | return 1; | |||||||||||||||||
| 143 | } | ||||||||||||||||||
| 144 | |||||||||||||||||||
| 145 | # | ||||||||||||||||||
| 146 | # logconfess | ||||||||||||||||||
| 147 | # | ||||||||||||||||||
| 148 | # Fatal error, with stack trace | ||||||||||||||||||
| 149 | # | ||||||||||||||||||
| 150 | 0 | ▶ | sub logconfess { | ||||||||||||||||
|
Subroutine
logconfess: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||
| 151 | 0 | my($self, $str) = @_; | |||||||||||||||||
| 152 | |||||||||||||||||||
| 153 | # log error to all drivers | ||||||||||||||||||
| 154 | 0 | $self->emit_carp('error', 'critical', 0, $str); | |||||||||||||||||
| 155 | |||||||||||||||||||
| 156 | 0 | die; | |||||||||||||||||
| 157 | } | ||||||||||||||||||
| 158 | |||||||||||||||||||
| 159 | # | ||||||||||||||||||
| 160 | # logcroak | ||||||||||||||||||
| 161 | # | ||||||||||||||||||
| 162 | # Fatal error | ||||||||||||||||||
| 163 | # | ||||||||||||||||||
| 164 | 0 | ▶ | sub logcroak { | ||||||||||||||||
|
Subroutine
logcroak: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||
| 165 | 0 | my($self, $str) = @_; | |||||||||||||||||
| 166 | |||||||||||||||||||
| 167 | # | ||||||||||||||||||
| 168 | # log error to all drivers | ||||||||||||||||||
| 169 | # | ||||||||||||||||||
| 170 | 0 | $self->emit_carp('error', 'critical', 0, $str); | |||||||||||||||||
| 171 | |||||||||||||||||||
| 172 | 0 | die; | |||||||||||||||||
| 173 | } | ||||||||||||||||||
| 174 | |||||||||||||||||||
| 175 | # | ||||||||||||||||||
| 176 | # logxcroak | ||||||||||||||||||
| 177 | # | ||||||||||||||||||
| 178 | # Fatal error, from perspective of caller | ||||||||||||||||||
| 179 | # | ||||||||||||||||||
| 180 | 0 | ▶ | sub logxcroak { | ||||||||||||||||
|
Subroutine
logxcroak: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||
| 181 | 0 | my($self, $offset, $str) = @_; | |||||||||||||||||
| 182 | |||||||||||||||||||
| 183 | # | ||||||||||||||||||
| 184 | # log error to all drivers | ||||||||||||||||||
| 185 | # | ||||||||||||||||||
| 186 | 0 | $self->emit_carp('error', 'critical', $offset, $str); | |||||||||||||||||
| 187 | |||||||||||||||||||
| 188 | 0 | die; | |||||||||||||||||
| 189 | } | ||||||||||||||||||
| 190 | |||||||||||||||||||
| 191 | # | ||||||||||||||||||
| 192 | # logdie | ||||||||||||||||||
| 193 | # | ||||||||||||||||||
| 194 | # Fatal error | ||||||||||||||||||
| 195 | # | ||||||||||||||||||
| 196 | 1 | ▶ | sub logdie { | ||||||||||||||||
|
Subroutine
logdie: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||
| 197 | 1 | my ($self, $str) = @_; | |||||||||||||||||
| 198 | |||||||||||||||||||
| 199 | # | ||||||||||||||||||
| 200 | # log error to all drivers | ||||||||||||||||||
| 201 | # | ||||||||||||||||||
| 202 | 1 | $self->emit('error', 'critical', $str); | |||||||||||||||||
| 203 | 1 | die; | |||||||||||||||||
| 204 | } | ||||||||||||||||||
| 205 | |||||||||||||||||||
| 206 | # | ||||||||||||||||||
| 207 | # logerr | ||||||||||||||||||
| 208 | # | ||||||||||||||||||
| 209 | # Signal error on stderr | ||||||||||||||||||
| 210 | # | ||||||||||||||||||
| 211 | 1 | ▶ | sub logerr { | ||||||||||||||||
|
Subroutine
logerr: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||
| 212 | 1 | my ($self, $str) = @_; | |||||||||||||||||
| 213 | |||||||||||||||||||
| 214 | # | ||||||||||||||||||
| 215 | # log error to all drivers | ||||||||||||||||||
| 216 | # | ||||||||||||||||||
| 217 | 1 | $self->emit('error', 'error', $str); | |||||||||||||||||
| 218 | } | ||||||||||||||||||
| 219 | |||||||||||||||||||
| 220 | # | ||||||||||||||||||
| 221 | # logwarn | ||||||||||||||||||
| 222 | # | ||||||||||||||||||
| 223 | # Warn, with "WARNING" clearly emphasized | ||||||||||||||||||
| 224 | # | ||||||||||||||||||
| 225 | 1 | ▶ | sub logwarn { | ||||||||||||||||
|
Subroutine
logwarn: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||
| 226 | 1 | my ($self, $str) = @_; | |||||||||||||||||
| 227 | |||||||||||||||||||
| 228 | # | ||||||||||||||||||
| 229 | # log error to all drivers | ||||||||||||||||||
| 230 | # | ||||||||||||||||||
| 231 | 1 | $self->emit('error', 'warning', $str); | |||||||||||||||||
| 232 | } | ||||||||||||||||||
| 233 | |||||||||||||||||||
| 234 | # | ||||||||||||||||||
| 235 | # logcluck | ||||||||||||||||||
| 236 | # | ||||||||||||||||||
| 237 | # Warning, with stack trace | ||||||||||||||||||
| 238 | # | ||||||||||||||||||
| 239 | 0 | ▶ | sub logcluck { | ||||||||||||||||
|
Subroutine
logcluck: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||
| 240 | 0 | my($self, $str) = @_; | |||||||||||||||||
| 241 | |||||||||||||||||||
| 242 | # log error to all drivers | ||||||||||||||||||
| 243 | 0 | $self->emit_carp('error', 'warning', 0, $str); | |||||||||||||||||
| 244 | } | ||||||||||||||||||
| 245 | |||||||||||||||||||
| 246 | # | ||||||||||||||||||
| 247 | # logcarp | ||||||||||||||||||
| 248 | # | ||||||||||||||||||
| 249 | # log a warning, carp-style | ||||||||||||||||||
| 250 | # | ||||||||||||||||||
| 251 | 0 | ▶ | sub logcarp { | ||||||||||||||||
|
Subroutine
logcarp: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||
| 252 | 0 | my($self, $str) = @_; | |||||||||||||||||
| 253 | |||||||||||||||||||
| 254 | # | ||||||||||||||||||
| 255 | # log message to all drivers | ||||||||||||||||||
| 256 | # | ||||||||||||||||||
| 257 | 0 | $self->emit_carp('error', 'warning', 0, $str); | |||||||||||||||||
| 258 | } | ||||||||||||||||||
| 259 | |||||||||||||||||||
| 260 | # | ||||||||||||||||||
| 261 | # logxcarp | ||||||||||||||||||
| 262 | # | ||||||||||||||||||
| 263 | # Warn from perspective of caller | ||||||||||||||||||
| 264 | # | ||||||||||||||||||
| 265 | 11 | ▶ | sub logxcarp { | ||||||||||||||||
|
Subroutine
logxcarp: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||
| 266 | 11 | my($self, $offset, $str) = @_; | |||||||||||||||||
| 267 | |||||||||||||||||||
| 268 | # | ||||||||||||||||||
| 269 | # log message to all drivers | ||||||||||||||||||
| 270 | # | ||||||||||||||||||
| 271 | 11 | $self->emit_carp('error', 'warning', $offset, $str); | |||||||||||||||||
| 272 | } | ||||||||||||||||||
| 273 | |||||||||||||||||||
| 274 | # | ||||||||||||||||||
| 275 | # logsay | ||||||||||||||||||
| 276 | # | ||||||||||||||||||
| 277 | # Log message to "output" channel at "notice" priority | ||||||||||||||||||
| 278 | # | ||||||||||||||||||
| 279 | 1 | ▶ | sub logsay { | ||||||||||||||||
|
Subroutine
logsay: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||
| 280 | 1 | my($self, $str) = @_; | |||||||||||||||||
| 281 | |||||||||||||||||||
| 282 | # | ||||||||||||||||||
| 283 | # send message to drivers | ||||||||||||||||||
| 284 | # | ||||||||||||||||||
| 285 | 1 | $self->emit('output', 'notice', $str); | |||||||||||||||||
| 286 | } | ||||||||||||||||||
| 287 | |||||||||||||||||||
| 288 | # | ||||||||||||||||||
| 289 | # loginfo | ||||||||||||||||||
| 290 | # | ||||||||||||||||||
| 291 | # Log message to "output" channel at "info" priority | ||||||||||||||||||
| 292 | # | ||||||||||||||||||
| 293 | 1 | ▶ | sub loginfo { | ||||||||||||||||
|
Subroutine
loginfo: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||
| 294 | 1 | my($self, $str) = @_; | |||||||||||||||||
| 295 | |||||||||||||||||||
| 296 | # | ||||||||||||||||||
| 297 | # send message to drivers | ||||||||||||||||||
| 298 | # | ||||||||||||||||||
| 299 | 1 | $self->emit('output', 'info', $str); | |||||||||||||||||
| 300 | } | ||||||||||||||||||
| 301 | |||||||||||||||||||
| 302 | # | ||||||||||||||||||
| 303 | # logdebug | ||||||||||||||||||
| 304 | # | ||||||||||||||||||
| 305 | # Log message to "output" channel at "debug" priority | ||||||||||||||||||
| 306 | # | ||||||||||||||||||
| 307 | 1 | ▶ | sub logdebug { | ||||||||||||||||
|
Subroutine
logdebug: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||
| 308 | 1 | my($self, $str) = @_; | |||||||||||||||||
| 309 | |||||||||||||||||||
| 310 | # | ||||||||||||||||||
| 311 | # send message to drivers | ||||||||||||||||||
| 312 | # | ||||||||||||||||||
| 313 | 1 | $self->emit('output', 'debug', $str); | |||||||||||||||||
| 314 | } | ||||||||||||||||||
| 315 | |||||||||||||||||||
| 316 | 2 | 1; # for require | |||||||||||||||||
| 317 | __END__ | ||||||||||||||||||