| 1 | ########################################################################### | ||||||||||||||||||||||||||||
| 2 | # | ||||||||||||||||||||||||||||
| 3 | # File.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 | 8 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 8 | require Log::Agent::Driver; | |||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | ######################################################################## | ||||||||||||||||||||||||||||
| 18 | package Log::Agent::Driver::File; | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 8 | ▶ | use vars qw(@ISA); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 8 | @ISA = qw(Log::Agent::Driver); | |||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | # | ||||||||||||||||||||||||||||
| 25 | # ->make -- defined | ||||||||||||||||||||||||||||
| 26 | # | ||||||||||||||||||||||||||||
| 27 | # Creation routine. | ||||||||||||||||||||||||||||
| 28 | # | ||||||||||||||||||||||||||||
| 29 | # Attributes (and switches that set them): | ||||||||||||||||||||||||||||
| 30 | # | ||||||||||||||||||||||||||||
| 31 | # prefix the application name | ||||||||||||||||||||||||||||
| 32 | # duperr whether to duplicate "error" channels to "output" | ||||||||||||||||||||||||||||
| 33 | # stampfmt stamping format ("syslog", "date", "own", "none") or closure | ||||||||||||||||||||||||||||
| 34 | # showpid whether to show pid after prefix in [] | ||||||||||||||||||||||||||||
| 35 | # channels where each channel ("error", "output", "debug") goes | ||||||||||||||||||||||||||||
| 36 | # chanperm what permissions each channel ("error", "output", "debug") has | ||||||||||||||||||||||||||||
| 37 | # magic_open flag to tell whether ">>file" or "|proc" are allowed filenames | ||||||||||||||||||||||||||||
| 38 | # rotate default rotating policy for logfiles | ||||||||||||||||||||||||||||
| 39 | # | ||||||||||||||||||||||||||||
| 40 | # Additional switches: | ||||||||||||||||||||||||||||
| 41 | # | ||||||||||||||||||||||||||||
| 42 | # file sole channel, implies -duperr = 0 and supersedes -channels | ||||||||||||||||||||||||||||
| 43 | # perm file permissions that supersedes all channel permissions | ||||||||||||||||||||||||||||
| 44 | # | ||||||||||||||||||||||||||||
| 45 | # Other attributes: | ||||||||||||||||||||||||||||
| 46 | # | ||||||||||||||||||||||||||||
| 47 | # channel_obj opened channel objects | ||||||||||||||||||||||||||||
| 48 | # | ||||||||||||||||||||||||||||
| 49 | 21 | ▶ | sub make { | ||||||||||||||||||||||||||
|
Subroutine
make: called CC=16 SCAR=30.8
Pod
documented
| |||||||||||||||||||||||||||||
| 50 | 21 | my $self = bless {}, shift; | |||||||||||||||||||||||||||
| 51 | 21 | my (%args) = @_; | |||||||||||||||||||||||||||
| 52 | 21 | my $prefix; | |||||||||||||||||||||||||||
| 53 | my $file; | ||||||||||||||||||||||||||||
| 54 | 21 | my $perm; | |||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | my %set = ( | ||||||||||||||||||||||||||||
| 57 | -prefix => \$prefix, # Handled by parent via _init | ||||||||||||||||||||||||||||
| 58 | -duperr => \$self->{'duperr'}, | ||||||||||||||||||||||||||||
| 59 | -channels => \$self->{'channels'}, | ||||||||||||||||||||||||||||
| 60 | -chanperm => \$self->{'chanperm'}, | ||||||||||||||||||||||||||||
| 61 | -stampfmt => \$self->{'stampfmt'}, | ||||||||||||||||||||||||||||
| 62 | -showpid => \$self->{'showpid'}, | ||||||||||||||||||||||||||||
| 63 | -magic_open => \$self->{'magic_open'}, | ||||||||||||||||||||||||||||
| 64 | -file => \$file, | ||||||||||||||||||||||||||||
| 65 | -perm => \$perm, | ||||||||||||||||||||||||||||
| 66 | 21 | -rotate => \$self->{'rotate'}, | |||||||||||||||||||||||||||
| 67 | ); | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 21 | ▶ | while (my ($arg, $val) = each %args) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 70 | 52 | my $vset = $set{lc($arg)}; | |||||||||||||||||||||||||||
| 71 | 52 | ▶ | unless (ref $vset) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 72 | 0 | require Carp; | |||||||||||||||||||||||||||
| 73 | 0 | Carp::croak("Unknown switch $arg"); | |||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | 52 | $$vset = $val; | |||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | # | ||||||||||||||||||||||||||||
| 79 | # If -file was used, it supersedes -duperr and -channels | ||||||||||||||||||||||||||||
| 80 | # | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 21 | ▶ | if (defined $file && length $file) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $file and length $file
MC/DC50%1/2
defined $file and length $file
defined $file
length $file
Truth table66%2/3
A and B
A= defined $fileB= length $file
| |||||||||||||||||||||||||||||
| 83 | 6 | $self->{'channels'} = { | |||||||||||||||||||||||||||
| 84 | 'debug' => $file, | ||||||||||||||||||||||||||||
| 85 | 'output' => $file, | ||||||||||||||||||||||||||||
| 86 | 'error' => $file, | ||||||||||||||||||||||||||||
| 87 | }; | ||||||||||||||||||||||||||||
| 88 | 6 | $self->{'duperr'} = 0; | |||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | # | ||||||||||||||||||||||||||||
| 92 | # and we do something similar for file permissions | ||||||||||||||||||||||||||||
| 93 | # | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 21 | ▶ | if (defined $perm && length $perm) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $perm and length $perm
MC/DC50%1/2
defined $perm and length $perm
defined $perm
length $perm
Truth table66%2/3
A and B
A= defined $permB= length $perm
| |||||||||||||||||||||||||||||
| 96 | $self->{chanperm} = { | ||||||||||||||||||||||||||||
| 97 | 6 | debug => $perm, | |||||||||||||||||||||||||||
| 98 | output => $perm, | ||||||||||||||||||||||||||||
| 99 | error => $perm | ||||||||||||||||||||||||||||
| 100 | }; | ||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 21 | $self->_init($prefix, 0); # 1 is the skip Carp penalty for confess | |||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 21 | ▶ | $self->{channels} = {} unless $self->channels; # No defined channels | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 106 | 21 | ▶ | $self->{chanperm} = {} unless $self->chanperm; # No defined perms | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 107 | 21 | $self->{channel_obj} = {}; # No opened files | |||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | # | ||||||||||||||||||||||||||||
| 110 | # Check for logfile rotation, which can be specified on a global or | ||||||||||||||||||||||||||||
| 111 | # file by file basis. Since Log::Agent::Rotate is a separate extension, | ||||||||||||||||||||||||||||
| 112 | # it may not be installed. | ||||||||||||||||||||||||||||
| 113 | # | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | 21 | ▶ | my $use_rotate = defined($self->rotate) ? 1 : 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 116 | 21 | ▶ | unless ($use_rotate) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 117 | 21 | foreach my $chan (keys %{$self->channels}) { | |||||||||||||||||||||||||||
| 118 | 47 | ▶ | $use_rotate = 1 if ref $self->channels->{$chan} eq 'ARRAY'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 119 | 47 | ▶ | last if $use_rotate; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | 21 | ▶ | if ($use_rotate) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 124 | 0 | eval { | |||||||||||||||||||||||||||
| 125 | 0 | require Log::Agent::File::Rotate; | |||||||||||||||||||||||||||
| 126 | }; | ||||||||||||||||||||||||||||
| 127 | 0 | ▶ | if ($@) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 128 | 0 | warn $@; | |||||||||||||||||||||||||||
| 129 | 0 | require Carp; | |||||||||||||||||||||||||||
| 130 | 0 | Carp::croak("Must install Log::Agent::Rotate to use rotation"); | |||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | 21 | return $self; | |||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | # | ||||||||||||||||||||||||||||
| 138 | # Attribute access | ||||||||||||||||||||||||||||
| 139 | # | ||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | 37 | ▶ | sub duperr { $_[0]->{duperr} } | ||||||||||||||||||||||||||
|
Subroutine
duperr: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 142 | 128 | ▶ | sub channels { $_[0]->{channels} } | ||||||||||||||||||||||||||
|
Subroutine
channels: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 143 | 66 | ▶ | sub chanperm { $_[0]->{chanperm} } | ||||||||||||||||||||||||||
|
Subroutine
chanperm: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 144 | 125 | ▶ | sub channel_obj { $_[0]->{channel_obj} } | ||||||||||||||||||||||||||
|
Subroutine
channel_obj: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 145 | 35 | ▶ | sub stampfmt { $_[0]->{stampfmt} } | ||||||||||||||||||||||||||
|
Subroutine
stampfmt: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 146 | 35 | ▶ | sub showpid { $_[0]->{showpid} } | ||||||||||||||||||||||||||
|
Subroutine
showpid: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 147 | 33 | ▶ | sub magic_open { $_[0]->{magic_open} } | ||||||||||||||||||||||||||
|
Subroutine
magic_open: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 148 | 56 | ▶ | sub rotate { $_[0]->{rotate} } | ||||||||||||||||||||||||||
|
Subroutine
rotate: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | # | ||||||||||||||||||||||||||||
| 151 | # ->prefix_msg -- defined | ||||||||||||||||||||||||||||
| 152 | # | ||||||||||||||||||||||||||||
| 153 | # NOP: channel handles prefixing for us. | ||||||||||||||||||||||||||||
| 154 | # | ||||||||||||||||||||||||||||
| 155 | 70 | ▶ | sub prefix_msg { | ||||||||||||||||||||||||||
|
Subroutine
prefix_msg: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 156 | 70 | my $self = shift; | |||||||||||||||||||||||||||
| 157 | 70 | return $_[0]; | |||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | # | ||||||||||||||||||||||||||||
| 161 | # ->chanfn | ||||||||||||||||||||||||||||
| 162 | # | ||||||||||||||||||||||||||||
| 163 | # Return channel file name. | ||||||||||||||||||||||||||||
| 164 | # | ||||||||||||||||||||||||||||
| 165 | 0 | ▶ | sub chanfn { | ||||||||||||||||||||||||||
|
Subroutine
chanfn: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 166 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 167 | 0 | my ($channel) = @_; | |||||||||||||||||||||||||||
| 168 | 0 | my $filename = $self->channels->{$channel}; | |||||||||||||||||||||||||||
| 169 | 0 | ▶ | if (ref $filename eq 'ARRAY') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 170 | 0 | $filename = $filename->[0]; | |||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||
| 172 | # No channel defined, use 'error' | ||||||||||||||||||||||||||||
| 173 | 0 | ▶ | $filename = $self->channels->{'error'} unless | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $filename and length $filename
MC/DC0%0/2
defined $filename and length $filename
defined $filename
length $filename
Truth table0%0/3
A and B
A= defined $filenameB= length $filename
| |||||||||||||||||||||||||||||
| 174 | defined $filename && length $filename; | ||||||||||||||||||||||||||||
| 175 | 0 | ▶ | $filename = '<STDERR>' unless defined $filename; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | 0 | return $filename; | |||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | # | ||||||||||||||||||||||||||||
| 181 | # ->channel_eq -- defined | ||||||||||||||||||||||||||||
| 182 | # | ||||||||||||||||||||||||||||
| 183 | # Compare two channels. | ||||||||||||||||||||||||||||
| 184 | # | ||||||||||||||||||||||||||||
| 185 | # It's hard to know for certain that two channels are equivalent, so we | ||||||||||||||||||||||||||||
| 186 | # compare filenames. This is not correct, of course, but it will do for | ||||||||||||||||||||||||||||
| 187 | # what we're trying to achieve here, namely avoid duplicates if possible | ||||||||||||||||||||||||||||
| 188 | # when traces are remapped to Carp::Datum. | ||||||||||||||||||||||||||||
| 189 | # | ||||||||||||||||||||||||||||
| 190 | 0 | ▶ | sub channel_eq { | ||||||||||||||||||||||||||
|
Subroutine
channel_eq: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 191 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 192 | 0 | my ($chan1, $chan2) = @_; | |||||||||||||||||||||||||||
| 193 | 0 | my $fn1 = $self->chanfn($chan1); | |||||||||||||||||||||||||||
| 194 | 0 | my $fn2 = $self->chanfn($chan2); | |||||||||||||||||||||||||||
| 195 | 0 | return $fn1 eq $fn2; | |||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||
| 198 | # | ||||||||||||||||||||||||||||
| 199 | # ->write -- defined | ||||||||||||||||||||||||||||
| 200 | # | ||||||||||||||||||||||||||||
| 201 | 77 | ▶ | sub write { | ||||||||||||||||||||||||||
|
Subroutine
write: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||
| 202 | 77 | my $self = shift; | |||||||||||||||||||||||||||
| 203 | 77 | my ($channel, $priority, $logstring) = @_; | |||||||||||||||||||||||||||
| 204 | 77 | my $chan = $self->channel($channel); | |||||||||||||||||||||||||||
| 205 | 77 | ▶ | return unless $chan; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||
| 207 | 77 | $chan->write($priority, $logstring); | |||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||
| 210 | # | ||||||||||||||||||||||||||||
| 211 | # ->channel | ||||||||||||||||||||||||||||
| 212 | # | ||||||||||||||||||||||||||||
| 213 | # Return channel object (one of the Log::Agent::Channel::* objects) | ||||||||||||||||||||||||||||
| 214 | # | ||||||||||||||||||||||||||||
| 215 | 77 | ▶ | sub channel { | ||||||||||||||||||||||||||
|
Subroutine
channel: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 216 | 77 | my $self = shift; | |||||||||||||||||||||||||||
| 217 | 77 | my ($name) = @_; | |||||||||||||||||||||||||||
| 218 | 77 | my $obj = $self->channel_obj->{$name}; | |||||||||||||||||||||||||||
| 219 | 77 | ▶ | $obj = $self->open_channel($name) unless $obj; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 220 | 77 | return $obj; | |||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||
| 224 | # | ||||||||||||||||||||||||||||
| 225 | # ->open_channel | ||||||||||||||||||||||||||||
| 226 | # | ||||||||||||||||||||||||||||
| 227 | # Open given channel according to the configured channel description and | ||||||||||||||||||||||||||||
| 228 | # return the object file descriptor. | ||||||||||||||||||||||||||||
| 229 | # | ||||||||||||||||||||||||||||
| 230 | # If no channel of that name was defined, use 'error' or STDERR. | ||||||||||||||||||||||||||||
| 231 | # | ||||||||||||||||||||||||||||
| 232 | 35 | ▶ | sub open_channel { | ||||||||||||||||||||||||||
|
Subroutine
open_channel: called CC=9 SCAR=22.3
Pod
undocumented
| |||||||||||||||||||||||||||||
| 233 | 35 | my $self = shift; | |||||||||||||||||||||||||||
| 234 | 35 | my ($name) = @_; | |||||||||||||||||||||||||||
| 235 | 35 | my $filename = $self->channels->{$name}; | |||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||
| 237 | # | ||||||||||||||||||||||||||||
| 238 | # Handle possible logfile rotation, which may be defined globally | ||||||||||||||||||||||||||||
| 239 | # or on a file by file basis. | ||||||||||||||||||||||||||||
| 240 | # | ||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||
| 242 | 35 | my $rotate; # A Log::Agent::Rotate object | |||||||||||||||||||||||||||
| 243 | 35 | ▶ | if (ref $filename eq 'ARRAY') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 244 | 0 | ($filename, $rotate) = @$filename; | |||||||||||||||||||||||||||
| 245 | } else { | ||||||||||||||||||||||||||||
| 246 | 35 | $rotate = $self->rotate; | |||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||
| 249 | 35 | my @common_args = ( | |||||||||||||||||||||||||||
| 250 | -prefix => $self->prefix, | ||||||||||||||||||||||||||||
| 251 | -stampfmt => $self->stampfmt, | ||||||||||||||||||||||||||||
| 252 | -showpid => $self->showpid, | ||||||||||||||||||||||||||||
| 253 | ); | ||||||||||||||||||||||||||||
| 254 | 35 | my @other_args; | |||||||||||||||||||||||||||
| 255 | my $type; | ||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||
| 257 | # | ||||||||||||||||||||||||||||
| 258 | # No channel defined, use 'error', or revert to STDERR | ||||||||||||||||||||||||||||
| 259 | # | ||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||
| 261 | 35 | ▶ | unless (defined $filename && length $filename) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $filename and length $filename
MC/DC50%1/2
defined $filename and length $filename
defined $filename
length $filename
Truth table66%2/3
A and B
A= defined $filenameB= length $filename
| |||||||||||||||||||||||||||||
| 262 | 4 | $filename = $self->channels->{'error'}; | |||||||||||||||||||||||||||
| 263 | 4 | ▶ | ($filename, $rotate) = @$filename if ref $filename eq 'ARRAY'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||
| 266 | 35 | ▶ | unless (defined $filename && length $filename) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $filename and length $filename
MC/DC50%1/2
defined $filename and length $filename
defined $filename
length $filename
Truth table66%2/3
A and B
A= defined $filenameB= length $filename
| |||||||||||||||||||||||||||||
| 267 | 2 | require Log::Agent::Channel::Handle; | |||||||||||||||||||||||||||
| 268 | 2 | select((select(main::STDERR), $| = 1)[0]); | |||||||||||||||||||||||||||
| 269 | 2 | $type = "Log::Agent::Channel::Handle"; | |||||||||||||||||||||||||||
| 270 | 2 | @other_args = (-handle => \*main::STDERR); | |||||||||||||||||||||||||||
| 271 | } else { | ||||||||||||||||||||||||||||
| 272 | 33 | require Log::Agent::Channel::File; | |||||||||||||||||||||||||||
| 273 | 33 | $type = "Log::Agent::Channel::File"; | |||||||||||||||||||||||||||
| 274 | 33 | @other_args = ( | |||||||||||||||||||||||||||
| 275 | -filename => $filename, | ||||||||||||||||||||||||||||
| 276 | -magic_open => $self->magic_open, | ||||||||||||||||||||||||||||
| 277 | -share => 1, | ||||||||||||||||||||||||||||
| 278 | ); | ||||||||||||||||||||||||||||
| 279 | push(@other_args, -fileperm => $self->chanperm->{$name}) | ||||||||||||||||||||||||||||
| 280 | 33 | ▶ | if $self->chanperm->{$name}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 281 | 33 | ▶ | push(@other_args, -rotate => $rotate) if ref $rotate; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||
| 284 | 35 | return $self->channel_obj->{$name} = | |||||||||||||||||||||||||||
| 285 | $type->make(@common_args, @other_args); | ||||||||||||||||||||||||||||
| 286 | } | ||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||
| 288 | # | ||||||||||||||||||||||||||||
| 289 | # ->emit_output | ||||||||||||||||||||||||||||
| 290 | # | ||||||||||||||||||||||||||||
| 291 | # Force error message to the regular 'output' channel with a specified tag. | ||||||||||||||||||||||||||||
| 292 | # | ||||||||||||||||||||||||||||
| 293 | 6 | ▶ | sub emit_output { | ||||||||||||||||||||||||||
|
Subroutine
emit_output: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 294 | 6 | my $self = shift; | |||||||||||||||||||||||||||
| 295 | 6 | my ($prio, $tag, $str) = @_; | |||||||||||||||||||||||||||
| 296 | 6 | my $cstr = $str->clone; # We're prepending tag on a copy | |||||||||||||||||||||||||||
| 297 | 6 | $cstr->prepend("$tag: "); | |||||||||||||||||||||||||||
| 298 | 6 | $self->write('output', $prio, $cstr); | |||||||||||||||||||||||||||
| 299 | } | ||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||
| 301 | ### | ||||||||||||||||||||||||||||
| 302 | ### Redefined routines to handle duperr | ||||||||||||||||||||||||||||
| 303 | ### | ||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||
| 305 | # | ||||||||||||||||||||||||||||
| 306 | # ->logconfess | ||||||||||||||||||||||||||||
| 307 | # | ||||||||||||||||||||||||||||
| 308 | # When `duperr' is true, emit message on the 'output' channel prefixed | ||||||||||||||||||||||||||||
| 309 | # with FATAL. | ||||||||||||||||||||||||||||
| 310 | # | ||||||||||||||||||||||||||||
| 311 | sub logconfess { | ||||||||||||||||||||||||||||
| 312 | my $self = shift; | ||||||||||||||||||||||||||||
| 313 | my ($str) = @_; | ||||||||||||||||||||||||||||
| 314 | $self->emit_output('critical', "FATAL", $str) if $self->duperr; | ||||||||||||||||||||||||||||
| 315 | $self->SUPER::logconfess($str); # Carp strips calls within hierarchy | ||||||||||||||||||||||||||||
| 316 | } | ||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||
| 318 | # | ||||||||||||||||||||||||||||
| 319 | # ->logxcroak | ||||||||||||||||||||||||||||
| 320 | # | ||||||||||||||||||||||||||||
| 321 | # When `duperr' is true, emit message on the 'output' channel prefixed | ||||||||||||||||||||||||||||
| 322 | # with FATAL. | ||||||||||||||||||||||||||||
| 323 | # | ||||||||||||||||||||||||||||
| 324 | 0 | ▶ | sub logxcroak { | ||||||||||||||||||||||||||
|
Subroutine
logxcroak: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 325 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 326 | 0 | my ($offset, $str) = @_; | |||||||||||||||||||||||||||
| 327 | 0 | my $msg = Log::Agent::Message->make( | |||||||||||||||||||||||||||
| 328 | $self->carpmess($offset, $str, \&Carp::shortmess) | ||||||||||||||||||||||||||||
| 329 | ); | ||||||||||||||||||||||||||||
| 330 | 0 | ▶ | $self->emit_output('critical', "FATAL", $msg) if $self->duperr; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||
| 332 | # | ||||||||||||||||||||||||||||
| 333 | # Carp strips calls within hierarchy, so that new call should not show, | ||||||||||||||||||||||||||||
| 334 | # there's no need to adjust the frame offset. | ||||||||||||||||||||||||||||
| 335 | # | ||||||||||||||||||||||||||||
| 336 | 0 | $self->SUPER::logdie($msg); | |||||||||||||||||||||||||||
| 337 | } | ||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||
| 339 | # | ||||||||||||||||||||||||||||
| 340 | # ->logdie | ||||||||||||||||||||||||||||
| 341 | # | ||||||||||||||||||||||||||||
| 342 | # When `duperr' is true, emit message on the 'output' channel prefixed | ||||||||||||||||||||||||||||
| 343 | # with FATAL. | ||||||||||||||||||||||||||||
| 344 | # | ||||||||||||||||||||||||||||
| 345 | 2 | ▶ | sub logdie { | ||||||||||||||||||||||||||
|
Subroutine
logdie: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 346 | 2 | my $self = shift; | |||||||||||||||||||||||||||
| 347 | 2 | my ($str) = @_; | |||||||||||||||||||||||||||
| 348 | 2 | ▶ | $self->emit_output('critical', "FATAL", $str) if $self->duperr; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 349 | 2 | $self->SUPER::logdie($str); | |||||||||||||||||||||||||||
| 350 | } | ||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||
| 352 | # | ||||||||||||||||||||||||||||
| 353 | # ->logerr | ||||||||||||||||||||||||||||
| 354 | # | ||||||||||||||||||||||||||||
| 355 | # When `duperr' is true, emit message on the 'output' channel prefixed | ||||||||||||||||||||||||||||
| 356 | # with ERROR. | ||||||||||||||||||||||||||||
| 357 | # | ||||||||||||||||||||||||||||
| 358 | 12 | ▶ | sub logerr { | ||||||||||||||||||||||||||
|
Subroutine
logerr: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 359 | 12 | my $self = shift; | |||||||||||||||||||||||||||
| 360 | 12 | my ($str) = @_; | |||||||||||||||||||||||||||
| 361 | 12 | ▶ | $self->emit_output('error', "ERROR", $str) if $self->duperr; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 362 | 12 | $self->SUPER::logerr($str); | |||||||||||||||||||||||||||
| 363 | } | ||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||
| 365 | # | ||||||||||||||||||||||||||||
| 366 | # ->logcluck | ||||||||||||||||||||||||||||
| 367 | # | ||||||||||||||||||||||||||||
| 368 | # When `duperr' is true, emit message on the 'output' channel prefixed | ||||||||||||||||||||||||||||
| 369 | # with WARNING. | ||||||||||||||||||||||||||||
| 370 | # | ||||||||||||||||||||||||||||
| 371 | 0 | ▶ | sub logconfess { | ||||||||||||||||||||||||||
|
Subroutine
logconfess: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 372 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 373 | 0 | my ($str) = @_; | |||||||||||||||||||||||||||
| 374 | 0 | ▶ | $self->emit_output('warning', "WARNING", $str) if $self->duperr; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 375 | 0 | $self->SUPER::logcluck($str); # Carp strips calls within hierarchy | |||||||||||||||||||||||||||
| 376 | } | ||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||
| 378 | # | ||||||||||||||||||||||||||||
| 379 | # ->logwarn | ||||||||||||||||||||||||||||
| 380 | # | ||||||||||||||||||||||||||||
| 381 | # When `duperr' is true, emit message on the 'output' channel prefixed | ||||||||||||||||||||||||||||
| 382 | # with WARNING. | ||||||||||||||||||||||||||||
| 383 | # | ||||||||||||||||||||||||||||
| 384 | 4 | ▶ | sub logwarn { | ||||||||||||||||||||||||||
|
Subroutine
logwarn: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 385 | 4 | my $self = shift; | |||||||||||||||||||||||||||
| 386 | 4 | my ($str) = @_; | |||||||||||||||||||||||||||
| 387 | 4 | ▶ | $self->emit_output('warning', "WARNING", $str) if $self->duperr; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 388 | 4 | $self->SUPER::logwarn($str); | |||||||||||||||||||||||||||
| 389 | } | ||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||
| 391 | # | ||||||||||||||||||||||||||||
| 392 | # ->logxcarp | ||||||||||||||||||||||||||||
| 393 | # | ||||||||||||||||||||||||||||
| 394 | # When `duperr' is true, emit message on the 'output' channel prefixed | ||||||||||||||||||||||||||||
| 395 | # with WARNING. | ||||||||||||||||||||||||||||
| 396 | # | ||||||||||||||||||||||||||||
| 397 | 13 | ▶ | sub logxcarp { | ||||||||||||||||||||||||||
|
Subroutine
logxcarp: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||
| 398 | 13 | my $self = shift; | |||||||||||||||||||||||||||
| 399 | 13 | my ($offset, $str) = @_; | |||||||||||||||||||||||||||
| 400 | 13 | my $msg = Log::Agent::Message->make( | |||||||||||||||||||||||||||
| 401 | $self->carpmess($offset, $str, \&Carp::shortmess) | ||||||||||||||||||||||||||||
| 402 | ); | ||||||||||||||||||||||||||||
| 403 | 13 | ▶ | $self->emit_output('warning', "WARNING", $msg) if $self->duperr; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 404 | 13 | $self->SUPER::logwarn($msg); | |||||||||||||||||||||||||||
| 405 | } | ||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||
| 407 | # | ||||||||||||||||||||||||||||
| 408 | # ->DESTROY | ||||||||||||||||||||||||||||
| 409 | # | ||||||||||||||||||||||||||||
| 410 | # Close all opened channels, so they may be removed from the common pool. | ||||||||||||||||||||||||||||
| 411 | # | ||||||||||||||||||||||||||||
| 412 | 13 | ▶ | sub DESTROY { | ||||||||||||||||||||||||||
|
Subroutine
DESTROY: called CC=4 SCAR=14.3
| |||||||||||||||||||||||||||||
| 413 | 13 | my $self = shift; | |||||||||||||||||||||||||||
| 414 | 13 | my $channel_obj = $self->channel_obj; | |||||||||||||||||||||||||||
| 415 | 13 | ▶ | return unless defined $channel_obj; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 416 | 13 | foreach my $chan (values %$channel_obj) { | |||||||||||||||||||||||||||
| 417 | 21 | ▶ | $chan->close if defined $chan; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 418 | } | ||||||||||||||||||||||||||||
| 419 | } | ||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||
| 421 | 8 | 1; # for require | |||||||||||||||||||||||||||
| 422 | __END__ | ||||||||||||||||||||||||||||