| 1 | ## -*- Mode: CPerl -*- | ||||||||||||||||||||||||||||||||||||||||||
| 2 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 3 | ## File: DTA::CAB::Logger.pm | ||||||||||||||||||||||||||||||||||||||||||
| 4 | ## Author: Bryan Jurish <moocow@cpan.org> | ||||||||||||||||||||||||||||||||||||||||||
| 5 | ## Description: DTA::CAB logging (using Log::Log4perl) | ||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | package DTA::CAB::Logger; | ||||||||||||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use DTA::CAB::Utils ':profile'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use Log::Log4perl; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use File::Basename; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | ##============================================================================== | ||||||||||||||||||||||||||||||||||||||||||
| 15 | ## Globals | ||||||||||||||||||||||||||||||||||||||||||
| 16 | ##============================================================================== | ||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | 1 | our @ISA = qw(); | |||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | 1 | our ($MIN_LEVEL); ##-- minimum log level | |||||||||||||||||||||||||||||||||||||||||
| 21 | 1 | our (%defaultLogOpts); ##-- default log options | |||||||||||||||||||||||||||||||||||||||||
| 22 | 1 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=5 SCAR=18.2
| |||||||||||||||||||||||||||||||||||||||||||
| 23 | 1 | $MIN_LEVEL = $Log::Log4perl::Level::LEVELS{(sort {$a<=>$b} keys(%Log::Log4perl::Level::LEVELS))[0]}; | |||||||||||||||||||||||||||||||||||||||||
| 24 | 1 | ▶ | %defaultLogOpts = | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | ( | ||||||||||||||||||||||||||||||||||||||||||
| 26 | l4pfile => undef, ##-- formerly $logConfigFile | ||||||||||||||||||||||||||||||||||||||||||
| 27 | watch => undef, ##-- watch l4pfile (undef or secs)? | ||||||||||||||||||||||||||||||||||||||||||
| 28 | rootLevel => ($^W ? 'WARN' : 'FATAL'), | ||||||||||||||||||||||||||||||||||||||||||
| 29 | twLevel => 'INFO', ##-- log level for DTA::TokWrap (used by DTA::CAB::Format::TEI) | ||||||||||||||||||||||||||||||||||||||||||
| 30 | level => ($^W ? $MIN_LEVEL : 'INFO'), | ||||||||||||||||||||||||||||||||||||||||||
| 31 | stderr => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 32 | logdate => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 33 | logtime => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 34 | file => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 35 | rotate => undef, ##-- default: haveFileRotate() | ||||||||||||||||||||||||||||||||||||||||||
| 36 | syslog => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 37 | sysLevel => ($^W ? 'debug' : 'info'), | ||||||||||||||||||||||||||||||||||||||||||
| 38 | sysName => File::Basename::basename($0), | ||||||||||||||||||||||||||||||||||||||||||
| 39 | sysIdent => undef, ##-- default=$opts{sysName} | ||||||||||||||||||||||||||||||||||||||||||
| 40 | sysFacility => ($0 =~ m/(?:server|daemon)/i ? 'daemon' : 'user'), | ||||||||||||||||||||||||||||||||||||||||||
| 41 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | ## $DEFAULT_LOG_CONF = PACKAGE->defaultLogConf(%opts) | ||||||||||||||||||||||||||||||||||||||||||
| 45 | ## + default configuration for Log::Log4perl | ||||||||||||||||||||||||||||||||||||||||||
| 46 | ## + see Log::Log4perl(3pm), Log::Log4perl::Config(3pm) for details | ||||||||||||||||||||||||||||||||||||||||||
| 47 | ## + %opts: | ||||||||||||||||||||||||||||||||||||||||||
| 48 | ## rootLevel => $LEVEL_OR_UNDEF, ##-- min root log level (default='WARN' or 'FATAL', depending on $^W) | ||||||||||||||||||||||||||||||||||||||||||
| 49 | ## level => $LEVEL_OR_UNDEF, ##-- min log level (default=$MIN_LEVEL or 'INFO', depending on $^W) | ||||||||||||||||||||||||||||||||||||||||||
| 50 | ## stderr => $bool, ##-- whether to log to stderr (default=1) | ||||||||||||||||||||||||||||||||||||||||||
| 51 | ## logtime => $bool, ##-- whether to log time-stamps on stderr (default=0) | ||||||||||||||||||||||||||||||||||||||||||
| 52 | ## logdate => $bool, ##-- whether to log date+time-stamps on stderr (default=0) | ||||||||||||||||||||||||||||||||||||||||||
| 53 | ## file => $filename, ##-- log to $filename if true | ||||||||||||||||||||||||||||||||||||||||||
| 54 | ## rotate => $bool, ##-- use Log::Dispatch::FileRotate if available and $filename is true | ||||||||||||||||||||||||||||||||||||||||||
| 55 | ## syslog => $bool, ##-- use Log::Dispatch::Syslog if available and true (default=false) | ||||||||||||||||||||||||||||||||||||||||||
| 56 | ## sysLevel => $level, ##-- minimum level for syslog (default='debug' or 'info', depending on $^W) | ||||||||||||||||||||||||||||||||||||||||||
| 57 | ## ## : available levels: debug,info,notice,warning,error,critical,alert,emergency (== 0..7) | ||||||||||||||||||||||||||||||||||||||||||
| 58 | ## sysName => $sysName, ##-- name for syslog (default=basename($0)) | ||||||||||||||||||||||||||||||||||||||||||
| 59 | ## sysIdent => $sysIdent, ##-- ident string for syslog (default=$sysName) | ||||||||||||||||||||||||||||||||||||||||||
| 60 | ## sysFacility => $facility, ##-- facility for syslog (default='daemon') | ||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | ▶ | sub defaultLogConf { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
defaultLogConf: not called CC=25 SCAR=64.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | my ($that,%opts) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | %opts = (%defaultLogOpts,%opts); | |||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | ▶ | $opts{rotate} = haveFileRotate() if (defined($opts{file}) && !defined($opts{rotate})); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $opts{"file"} and not defined $opts{"rotate"}
MC/DC0%0/2
defined $opts{"file"} and not defined $opts{"rotate"}
defined $opts{"file"}
not defined $opts{"rotate"}
Truth table0%0/3
A and not(B)
A= defined $opts{"file"}B= not defined $opts{"rotate"}
| |||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | ▶ | $opts{sysIdent} = $opts{sysName} if (!defined($opts{sysIdent})); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | ##-- generate base config | ||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | my $cfg = " | |||||||||||||||||||||||||||||||||||||||||
| 70 | ##-- Loggers | ||||||||||||||||||||||||||||||||||||||||||
| 71 | log4perl.oneMessagePerAppender = 1 ##-- suppress duplicate messages to the same appender | ||||||||||||||||||||||||||||||||||||||||||
| 72 | "; | ||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | ▶ | if ($opts{rootLevel} && $opts{rootLevel} ne 'OFF') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$opts{"rootLevel"} and $opts{"rootLevel"} ne "OFF"
MC/DC0%0/2
$opts{"rootLevel"} and $opts{"rootLevel"} ne "OFF"
$opts{"rootLevel"}
$opts{"rootLevel"} ne "OFF"
Truth table0%0/3
A and B
A= $opts{"rootLevel"}B= $opts{"rootLevel"} ne "OFF"
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | ##-- root logger | ||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | $cfg .= "log4perl.rootLogger = $opts{rootLevel}, AppStderr\n"; | |||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | ▶ | if ($opts{stderr} || $opts{file} || $opts{syslog}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$opts{"stderr"} or $opts{"file"} or $opts{"syslog"}
$opts{"stderr"} or $opts{"file"}
MC/DC0%0/3
$opts{"stderr"} or $opts{"file"} or $opts{"syslog"}
$opts{"stderr"}
$opts{"file"}
$opts{"syslog"}
Truth table0%0/4
A or B or C
A= $opts{"stderr"}B= $opts{"file"}C= $opts{"syslog"}
| |||||||||||||||||||||||||||||||||||||||||||
| 80 | ##-- tokwrap logger | ||||||||||||||||||||||||||||||||||||||||||
| 81 | $cfg .= "log4perl.logger.DTA.TokWrap = $opts{twLevel}, ".join(", ", | ||||||||||||||||||||||||||||||||||||||||||
| 82 | ($opts{stderr} ? 'AppStderr' : qw()), | ||||||||||||||||||||||||||||||||||||||||||
| 83 | ($opts{file} ? 'AppFile' : qw()), | ||||||||||||||||||||||||||||||||||||||||||
| 84 | ($opts{syslog} ? 'AppSyslog' : qw()), | ||||||||||||||||||||||||||||||||||||||||||
| 85 | )."\n" | ||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | ▶ | if ($opts{twLevel}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 87 | ##-- local package logger | ||||||||||||||||||||||||||||||||||||||||||
| 88 | $cfg .= "log4perl.logger.DTA.CAB = $opts{level}, ".join(", ", | ||||||||||||||||||||||||||||||||||||||||||
| 89 | ($opts{stderr} ? 'AppStderr' : qw()), | ||||||||||||||||||||||||||||||||||||||||||
| 90 | ($opts{file} ? 'AppFile' : qw()), | ||||||||||||||||||||||||||||||||||||||||||
| 91 | ($opts{syslog} ? 'AppSyslog' : qw()), | ||||||||||||||||||||||||||||||||||||||||||
| 92 | )."\n" | ||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | ▶ | if ($opts{level}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||
| 95 | ##-- avoid duplicate messages | ||||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | $cfg .= "log4perl.additivity.DTA = 0\n"; | |||||||||||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||
| 99 | ##-- appenders: utils | ||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | $cfg .= " | |||||||||||||||||||||||||||||||||||||||||
| 101 | ##-- Appenders: Utilities | ||||||||||||||||||||||||||||||||||||||||||
| 102 | log4perl.PatternLayout.cspec.G = sub { return File::Basename::basename(\"$::0\"); } | ||||||||||||||||||||||||||||||||||||||||||
| 103 | "; | ||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||
| 105 | ##-- appender: stderr | ||||||||||||||||||||||||||||||||||||||||||
| 106 | my $stderr_date = ($opts{logdate} ? '%d{yyyy-MM-dd HH:mm:ss} ' | ||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | ▶ | : ($opts{logtime} ? '%d{HH:mm:ss} ' : '')); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | $cfg .= " | |||||||||||||||||||||||||||||||||||||||||
| 109 | ##-- Appender: AppStderr | ||||||||||||||||||||||||||||||||||||||||||
| 110 | log4perl.appender.AppStderr = Log::Log4perl::Appender::Screen | ||||||||||||||||||||||||||||||||||||||||||
| 111 | log4perl.appender.AppStderr.stderr = 1 | ||||||||||||||||||||||||||||||||||||||||||
| 112 | log4perl.appender.AppStderr.binmode = :utf8 | ||||||||||||||||||||||||||||||||||||||||||
| 113 | log4perl.appender.AppStderr.layout = Log::Log4perl::Layout::PatternLayout | ||||||||||||||||||||||||||||||||||||||||||
| 114 | log4perl.appender.AppStderr.layout.ConversionPattern = ${stderr_date}%G[%P] %p: %c: %m%n | ||||||||||||||||||||||||||||||||||||||||||
| 115 | "; | ||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||
| 117 | ##-- appender: syslog | ||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | ▶ | if ($opts{syslog}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | eval 'use Log::Dispatch::Syslog;'; | |||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | ▶ | die "could not use Log::Dispatch::Syslog: $@" if ($@); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | $cfg .= " | |||||||||||||||||||||||||||||||||||||||||
| 122 | log4perl.appender.AppSyslog = Log::Dispatch::Syslog | ||||||||||||||||||||||||||||||||||||||||||
| 123 | log4perl.appender.AppSyslog.name = $opts{sysName} | ||||||||||||||||||||||||||||||||||||||||||
| 124 | log4perl.appender.AppSyslog.ident = $opts{sysIdent} | ||||||||||||||||||||||||||||||||||||||||||
| 125 | log4perl.appender.AppSyslog.min_level = $opts{sysLevel} | ||||||||||||||||||||||||||||||||||||||||||
| 126 | log4perl.appender.AppSyslog.facility = $opts{sysFacility} | ||||||||||||||||||||||||||||||||||||||||||
| 127 | log4perl.appender.AppSyslog.logopt = pid | ||||||||||||||||||||||||||||||||||||||||||
| 128 | log4perl.appender.AppSyslog.layout = Log::Log4perl::Layout::PatternLayout | ||||||||||||||||||||||||||||||||||||||||||
| 129 | log4perl.appender.AppSyslog.layout.ConversionPattern = (%p) %c: %m%n | ||||||||||||||||||||||||||||||||||||||||||
| 130 | "; | ||||||||||||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | ▶ | if ($opts{file} && $opts{rotate}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
$opts{"file"} and $opts{"rotate"}
MC/DC0%0/2
$opts{"file"} and $opts{"rotate"}
$opts{"file"}
$opts{"rotate"}
Truth table0%0/3
A and B
A= $opts{"file"}B= $opts{"rotate"}
| |||||||||||||||||||||||||||||||||||||||||||
| 134 | ##-- rotating file appender | ||||||||||||||||||||||||||||||||||||||||||
| 135 | 0 | eval 'use Log::Dispatch::FileRotate;'; | |||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | ▶ | die "could not use Log::Dispatch::FileRotate: $@" if ($@); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | $cfg .= " | |||||||||||||||||||||||||||||||||||||||||
| 138 | ##-- Appender: AppFile: rotating file appender | ||||||||||||||||||||||||||||||||||||||||||
| 139 | log4perl.appender.AppFile = Log::Dispatch::FileRotate | ||||||||||||||||||||||||||||||||||||||||||
| 140 | log4perl.appender.AppFile.min_level = debug | ||||||||||||||||||||||||||||||||||||||||||
| 141 | log4perl.appender.AppFile.filename = $opts{file} | ||||||||||||||||||||||||||||||||||||||||||
| 142 | log4perl.appender.AppFile.binmode = :utf8 | ||||||||||||||||||||||||||||||||||||||||||
| 143 | log4perl.appender.AppFile.mode = append | ||||||||||||||||||||||||||||||||||||||||||
| 144 | log4perl.appender.AppFile.size = 10485760 | ||||||||||||||||||||||||||||||||||||||||||
| 145 | log4perl.appender.AppFile.max = 10 | ||||||||||||||||||||||||||||||||||||||||||
| 146 | log4perl.appender.AppFile.layout = Log::Log4perl::Layout::PatternLayout | ||||||||||||||||||||||||||||||||||||||||||
| 147 | log4perl.appender.AppFile.layout.ConversionPattern = %d{yyyy-MM-dd HH:mm:ss} [%P] (%p) %c: %m%n | ||||||||||||||||||||||||||||||||||||||||||
| 148 | "; | ||||||||||||||||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||||||||||||||||
| 150 | elsif ($opts{file}) { | ||||||||||||||||||||||||||||||||||||||||||
| 151 | ##-- raw file appender | ||||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | $cfg .= " | |||||||||||||||||||||||||||||||||||||||||
| 153 | ##-- Appender: AppFile: raw file appender (no automatic log rotation) | ||||||||||||||||||||||||||||||||||||||||||
| 154 | log4perl.appender.AppFile = Log::Log4perl::Appender::File | ||||||||||||||||||||||||||||||||||||||||||
| 155 | log4perl.appender.AppFile.filename = $opts{file} | ||||||||||||||||||||||||||||||||||||||||||
| 156 | log4perl.appender.AppFile.mode = append | ||||||||||||||||||||||||||||||||||||||||||
| 157 | log4perl.appender.AppFile.utf8 = 1 | ||||||||||||||||||||||||||||||||||||||||||
| 158 | log4perl.appender.AppFile.layout = Log::Log4perl::Layout::PatternLayout | ||||||||||||||||||||||||||||||||||||||||||
| 159 | log4perl.appender.AppFile.layout.ConversionPattern = %d{yyyy-MM-dd HH:mm:ss} [%P] (%p) %c: %m%n | ||||||||||||||||||||||||||||||||||||||||||
| 160 | "; | ||||||||||||||||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||
| 163 | #print STDERR "$cfg\n"; ##--debug | ||||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | return $cfg; | |||||||||||||||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||
| 167 | ## $bool = CLASS::haveFileRotate() | ||||||||||||||||||||||||||||||||||||||||||
| 168 | ## + returns true if Log::Dispatch::FileRotate is available | ||||||||||||||||||||||||||||||||||||||||||
| 169 | 0 | ▶ | sub haveFileRotate { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
haveFileRotate: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 170 | 0 | ▶ | return 1 if (defined($Log::Dispatch::FileRotate::VERSION)); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 171 | 0 | eval "use Log::Dispatch::FileRotate;"; | |||||||||||||||||||||||||||||||||||||||||
| 172 | 0 | ▶ | return 1 if (defined($Log::Dispatch::FileRotate::VERSION) && !$@); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $Log::Dispatch::FileRotate::VERSION and not $@
MC/DC0%0/2
defined $Log::Dispatch::FileRotate::VERSION and not $@
defined $Log::Dispatch::FileRotate::VERSION
not $@
Truth table0%0/3
A and not(B)
A= defined $Log::Dispatch::FileRotate::VERSIONB= not $@
| |||||||||||||||||||||||||||||||||||||||||||
| 173 | 0 | $@=''; | |||||||||||||||||||||||||||||||||||||||||
| 174 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||
| 177 | ## $bool = CLASS::haveSyslog() | ||||||||||||||||||||||||||||||||||||||||||
| 178 | ## + returns true if Log::Dispatch::Syslog is available | ||||||||||||||||||||||||||||||||||||||||||
| 179 | 0 | ▶ | sub haveSyslog { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
haveSyslog: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 180 | 0 | ▶ | return 1 if (defined($Log::Dispatch::Syslog::VERSION)); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | eval "use Log::Dispatch::Syslog;"; | |||||||||||||||||||||||||||||||||||||||||
| 182 | 0 | ▶ | return 1 if (defined($Log::Dispatch::Syslog::VERSION) && !$@); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $Log::Dispatch::Syslog::VERSION and not $@
MC/DC0%0/2
defined $Log::Dispatch::Syslog::VERSION and not $@
defined $Log::Dispatch::Syslog::VERSION
not $@
Truth table0%0/3
A and not(B)
A= defined $Log::Dispatch::Syslog::VERSIONB= not $@
| |||||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | $@=''; | |||||||||||||||||||||||||||||||||||||||||
| 184 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||
| 187 | ##============================================================================== | ||||||||||||||||||||||||||||||||||||||||||
| 188 | ## Functions: Initialization | ||||||||||||||||||||||||||||||||||||||||||
| 189 | ##============================================================================== | ||||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||
| 191 | ## undef = PACKAGE->logInit(%opts) ##-- use default configuration with %opts | ||||||||||||||||||||||||||||||||||||||||||
| 192 | ## + %opts: see defaultLogConf() | ||||||||||||||||||||||||||||||||||||||||||
| 193 | ## + all log calls in the DTA::CAB namespace should use a subcategory of 'DTA::CAB' | ||||||||||||||||||||||||||||||||||||||||||
| 194 | ## + only needs to be called once; see Log::Log4perl->initialized() | ||||||||||||||||||||||||||||||||||||||||||
| 195 | 0 | ▶ | sub logInit { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
logInit: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 196 | 0 | my $that = shift; | |||||||||||||||||||||||||||||||||||||||||
| 197 | 0 | my %opts = (%defaultLogOpts,@_); | |||||||||||||||||||||||||||||||||||||||||
| 198 | 0 | binmode(\*STDERR,':utf8'); | |||||||||||||||||||||||||||||||||||||||||
| 199 | 0 | ▶ | if (!defined($opts{l4pfile})) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 200 | 0 | my $confstr = $that->defaultLogConf(%opts); | |||||||||||||||||||||||||||||||||||||||||
| 201 | 0 | Log::Log4perl::init(\$confstr); | |||||||||||||||||||||||||||||||||||||||||
| 202 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 203 | 0 | eval 'use Log::Dispatch::Syslog;'; | |||||||||||||||||||||||||||||||||||||||||
| 204 | 0 | eval 'use Log::Dispatch::FileRotate;'; | |||||||||||||||||||||||||||||||||||||||||
| 205 | 0 | ▶ | if (defined($opts{watch})) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | Log::Log4perl::init_and_watch($opts{l4pfile},$opts{watch}); | |||||||||||||||||||||||||||||||||||||||||
| 207 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 208 | 0 | Log::Log4perl::init($opts{l4pfile}); | |||||||||||||||||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||||||||||||||||
| 211 | #__PACKAGE__->info("initialized logging facility"); | ||||||||||||||||||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||||||||||||
| 214 | ## undef = PACKAGE->ensureLog(@args) ##-- ensure a Log::Log4perl has been initialized | ||||||||||||||||||||||||||||||||||||||||||
| 215 | 0 | ▶ | sub ensureLog { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ensureLog: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 216 | 0 | my $that = shift; | |||||||||||||||||||||||||||||||||||||||||
| 217 | 0 | ▶ | $that->logInit(@_) if (!Log::Log4perl->initialized); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||
| 220 | ##============================================================================== | ||||||||||||||||||||||||||||||||||||||||||
| 221 | ## Methods: get logger | ||||||||||||||||||||||||||||||||||||||||||
| 222 | ##============================================================================== | ||||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||
| 224 | ## $logger = $class_or_obj->logger() | ||||||||||||||||||||||||||||||||||||||||||
| 225 | ## $logger = $class_or_obj->logger($category) | ||||||||||||||||||||||||||||||||||||||||||
| 226 | ## + wrapper for Log::Log4perl::get_logger($category) | ||||||||||||||||||||||||||||||||||||||||||
| 227 | ## + $category defaults to ref($class_or_obj)||$class_or_obj | ||||||||||||||||||||||||||||||||||||||||||
| 228 | 0 | ▶ | sub logger { Log::Log4perl::get_logger(ref($_[0])||$_[0]); } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
logger: not called CC=2 SCAR=17.9
Pod
documented
Condition0%0/3
ref $_[0] || $_[0]
MC/DC0%0/2
ref $_[0] || $_[0]
ref $_[0]
$_[0]
Truth table0%0/3
A || B
A= ref $_[0]B= $_[0]
| |||||||||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||||||||
| 230 | ##============================================================================== | ||||||||||||||||||||||||||||||||||||||||||
| 231 | ## Methods: messages | ||||||||||||||||||||||||||||||||||||||||||
| 232 | ##============================================================================== | ||||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||
| 234 | ## undef = $class_or_obj->trace(@msg) | ||||||||||||||||||||||||||||||||||||||||||
| 235 | ## + be sure you have called Log::Log4perl::init() or similar first | ||||||||||||||||||||||||||||||||||||||||||
| 236 | ## - e.g. DTA::CAB::Logger::logInit() | ||||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | ▶ | sub trace { $_[0]->logger->trace(@_[1..$#_]); } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
trace: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 238 | 0 | ▶ | sub debug { $_[0]->logger->debug(@_[1..$#_]); } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
debug: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 239 | 0 | ▶ | sub info { $_[0]->logger->info(@_[1..$#_]); } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
info: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 240 | 0 | ▶ | sub warn { $_[0]->logger->warn(@_[1..$#_]); } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
warn: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 241 | 0 | ▶ | sub error { $_[0]->logger->error(@_[1..$#_]); } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
error: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 242 | 0 | ▶ | sub fatal { $_[0]->logger->fatal(@_[1..$#_]); } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fatal: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||||
| 244 | ## undef = $class_or_obj->llog($level, @msg) | ||||||||||||||||||||||||||||||||||||||||||
| 245 | ## + $level is some constant exported by Log::Log4perl::Level | ||||||||||||||||||||||||||||||||||||||||||
| 246 | 0 | ▶ | sub llog { $_[0]->logger->log(@_[1..$#_]); } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
llog: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||||||||||||
| 248 | ## undef = $class_or_obj->vlog($methodname_or_coderef_or_undef, @msg) | ||||||||||||||||||||||||||||||||||||||||||
| 249 | ## + calls $methodname_or_coderef_or_undef($class_or_obj,@msg) if defined | ||||||||||||||||||||||||||||||||||||||||||
| 250 | ## + e.g. $class_or_obj->vlog('trace', @msg) | ||||||||||||||||||||||||||||||||||||||||||
| 251 | 0 | ▶ | sub vlog { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
vlog: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 252 | 0 | ▶ | return if (!defined($_[1])); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 253 | 0 | ▶ | my $sub = UNIVERSAL::isa($_[1],'CODE') ? $_[1] : (UNIVERSAL::can($_[0],$_[1]) || UNIVERSAL::can($_[0],lc($_[1]))); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
UNIVERSAL::can($_[0], $_[1]) or UNIVERSAL::can($_[0], lc $_[1])
MC/DC0%0/2
UNIVERSAL::can($_[0], $_[1]) or UNIVERSAL::can($_[0], lc $_[1])
UNIVERSAL::can($_[0], $_[1])
UNIVERSAL::can($_[0], lc $_[1])
Truth table0%0/3
A or B
A= UNIVERSAL::can($_[0], $_[1])B= UNIVERSAL::can($_[0], lc $_[1])
| |||||||||||||||||||||||||||||||||||||||||||
| 254 | 0 | ▶ | return if (!defined($sub)); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 255 | 0 | return $sub->($_[0],@_[2..$#_]); | |||||||||||||||||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||||
| 258 | ##============================================================================== | ||||||||||||||||||||||||||||||||||||||||||
| 259 | ## Methods: carp & friends | ||||||||||||||||||||||||||||||||||||||||||
| 260 | ##============================================================================== | ||||||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||||
| 262 | ## undef = $class_or_obj->logcroak(@msg) | ||||||||||||||||||||||||||||||||||||||||||
| 263 | 0 | ▶ | sub logwarn { $_[0]->logger->logwarn(@_[1..$#_]); } # warn w/o stack trace | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
logwarn: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 264 | 0 | ▶ | sub logcarp { $_[0]->logger->logcarp(@_[1..$#_]); } # warn w/ 1-level stack trace | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
logcarp: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 265 | 0 | ▶ | sub logcluck { $_[0]->logger->logcluck(@_[1..$#_]); } # warn w/ full stack trace | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
logcluck: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||||||||||||
| 267 | 0 | ▶ | sub logdie { $_[0]->logger->logdie(@_[1..$#_]); } # die w/o stack trace | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
logdie: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 268 | 0 | ▶ | sub logcroak { $_[0]->logger->logcroak(@_[1..$#_]); } # die w/ 1-level stack trace | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
logcroak: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 269 | 0 | ▶ | sub logconfess { $_[0]->logger->logconfess(@_[1..$#_]); } # die w/ full stack trace | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
logconfess: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||||||||
| 272 | ##============================================================================== | ||||||||||||||||||||||||||||||||||||||||||
| 273 | ## Utils: Getopt::Long specification | ||||||||||||||||||||||||||||||||||||||||||
| 274 | ##============================================================================== | ||||||||||||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||||||||||||
| 276 | ## %getoptLongHash = $PACKAGE->cabLogOptions(%localOpts) | ||||||||||||||||||||||||||||||||||||||||||
| 277 | ## + %localOpts | ||||||||||||||||||||||||||||||||||||||||||
| 278 | ## verbose => $bool, ##-- if true, add 'verbose|v' as alias for 'log-level' | ||||||||||||||||||||||||||||||||||||||||||
| 279 | ## + adds support for logging options: | ||||||||||||||||||||||||||||||||||||||||||
| 280 | ## 'log-level|loglevel|ll|L=s' => \$defaultLogOpts{level}, | ||||||||||||||||||||||||||||||||||||||||||
| 281 | ## 'log-config|logconfig|log4perl-config|l4p-config|l4p=s' => \$defaultLogOpts{l4pfile}, | ||||||||||||||||||||||||||||||||||||||||||
| 282 | ## 'log-watch|logwatch|watch|lw=s' => \$defaultLogOpts{watch}, | ||||||||||||||||||||||||||||||||||||||||||
| 283 | ## 'nolog-watch|nologwatch|nowatch|nolw' => sub { $defaultLogOpts{watch}=undef; }, | ||||||||||||||||||||||||||||||||||||||||||
| 284 | ## 'log-stderr|stderr|lse!' => \$defaultLogOpts{stderr}, | ||||||||||||||||||||||||||||||||||||||||||
| 285 | ## 'log-file|lf=s' => \$defaultLogOpts{file}, | ||||||||||||||||||||||||||||||||||||||||||
| 286 | ## 'nolog-file|nolf' => sub { $defaultLogOpts{file}=undef; }, | ||||||||||||||||||||||||||||||||||||||||||
| 287 | ## 'log-rotate|rotate|lr!' => \$defaultLogOpts{rotate}, | ||||||||||||||||||||||||||||||||||||||||||
| 288 | ## 'log-syslog|syslog|ls!' => \$defaultLogOpts{syslog}, | ||||||||||||||||||||||||||||||||||||||||||
| 289 | ## 'log-option|logopt|lo=s' => \%defaultLogOpts, | ||||||||||||||||||||||||||||||||||||||||||
| 290 | 0 | ▶ | sub cabLogOptions { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
cabLogOptions: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 291 | 0 | my ($that,%opts) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 292 | return | ||||||||||||||||||||||||||||||||||||||||||
| 293 | (##-- Logging Options | ||||||||||||||||||||||||||||||||||||||||||
| 294 | 0 | ▶ | ($opts{verbose} ? ('verbose|v=s' => sub { $defaultLogOpts{level}=uc($_[1]); }) : qw()), | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 295 | 0 | ▶ | 'log-level|loglevel|ll|L=s' => sub { $defaultLogOpts{level}=uc($_[1]); }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 296 | 'log-config|logconfig|log4perl-config|l4p-config|l4p=s' => \$defaultLogOpts{l4pfile}, | ||||||||||||||||||||||||||||||||||||||||||
| 297 | 'log-watch|logwatch|watch|lw=s' => \$defaultLogOpts{watch}, | ||||||||||||||||||||||||||||||||||||||||||
| 298 | 0 | ▶ | 'nolog-watch|nologwatch|nowatch|nolw' => sub { $defaultLogOpts{watch}=undef; }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 299 | 'log-stderr|stderr|lse!' => \$defaultLogOpts{stderr}, | ||||||||||||||||||||||||||||||||||||||||||
| 300 | 'log-file|lf=s' => \$defaultLogOpts{file}, | ||||||||||||||||||||||||||||||||||||||||||
| 301 | 0 | ▶ | 'nolog-file|nolf' => sub { $defaultLogOpts{file}=undef; }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 302 | 'log-rotate|rotate|lr!' => \$defaultLogOpts{rotate}, | ||||||||||||||||||||||||||||||||||||||||||
| 303 | 'log-syslog|syslog|ls!' => \$defaultLogOpts{syslog}, | ||||||||||||||||||||||||||||||||||||||||||
| 304 | 0 | ▶ | 'log-option|logopt|lo=s%' => \%defaultLogOpts, | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 305 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 306 | } | ||||||||||||||||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||||||||||||||||
| 308 | ##============================================================================== | ||||||||||||||||||||||||||||||||||||||||||
| 309 | ## Utils: Profiling | ||||||||||||||||||||||||||||||||||||||||||
| 310 | ##============================================================================== | ||||||||||||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||||||||||||
| 312 | ## undef = $logger->logProfile($level, $elapsed_secs, $ntoks, $nchrs) | ||||||||||||||||||||||||||||||||||||||||||
| 313 | 0 | ▶ | sub logProfile { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
logProfile: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 314 | 0 | $_[0]->vlog($_[1], profile_str(@_[2..$#_])); | |||||||||||||||||||||||||||||||||||||||||
| 315 | } | ||||||||||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||||||||||||||
| 318 | 1 | 1; ##-- be happy | |||||||||||||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||||||||||||
| 320 | __END__ | ||||||||||||||||||||||||||||||||||||||||||