| 1 | ################################################## | ||||||||||||||||||||||||||||
| 2 | package Log::Log4perl; | ||||||||||||||||||||||||||||
| 3 | ################################################## | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 54 | ▶ | END { local($?); Log::Log4perl::Logger::cleanup(); } | ||||||||||||||||||||||||||
|
Subroutine
END: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 54 | ▶ | use 5.006; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 54 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 54 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 54 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 54 | ▶ | use Log::Log4perl::Util; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 54 | ▶ | use Log::Log4perl::Logger; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 54 | ▶ | use Log::Log4perl::Level; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 54 | ▶ | use Log::Log4perl::Config; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | 54 | ▶ | use Log::Log4perl::Appender; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 54 | our $VERSION = '1.58'; | |||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | # set this to '1' if you're using a wrapper | ||||||||||||||||||||||||||||
| 22 | # around Log::Log4perl | ||||||||||||||||||||||||||||
| 23 | 54 | our $caller_depth = 0; | |||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | #this is a mapping of convenience names to opcode masks used in | ||||||||||||||||||||||||||||
| 26 | #$ALLOWED_CODE_OPS_IN_CONFIG_FILE below | ||||||||||||||||||||||||||||
| 27 | 54 | our %ALLOWED_CODE_OPS = ( | |||||||||||||||||||||||||||
| 28 | 'safe' => [ ':browse' ], | ||||||||||||||||||||||||||||
| 29 | 'restrictive' => [ ':default' ], | ||||||||||||||||||||||||||||
| 30 | ); | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 54 | our %WRAPPERS_REGISTERED = map { $_ => 1 } qw(Log::Log4perl); | |||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | #set this to the opcodes which are allowed when | ||||||||||||||||||||||||||||
| 35 | #$ALLOW_CODE_IN_CONFIG_FILE is set to a true value | ||||||||||||||||||||||||||||
| 36 | #if undefined, there are no restrictions on code that can be | ||||||||||||||||||||||||||||
| 37 | #excuted | ||||||||||||||||||||||||||||
| 38 | 54 | our @ALLOWED_CODE_OPS_IN_CONFIG_FILE; | |||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | #this hash lists things that should be exported into the Safe | ||||||||||||||||||||||||||||
| 41 | #compartment. The keys are the package the symbol should be | ||||||||||||||||||||||||||||
| 42 | #exported from and the values are array references to the names | ||||||||||||||||||||||||||||
| 43 | #of the symbols (including the leading type specifier) | ||||||||||||||||||||||||||||
| 44 | 54 | our %VARS_SHARED_WITH_SAFE_COMPARTMENT = ( | |||||||||||||||||||||||||||
| 45 | main => [ '%ENV' ], | ||||||||||||||||||||||||||||
| 46 | ); | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | #setting this to a true value will allow Perl code to be executed | ||||||||||||||||||||||||||||
| 49 | #within the config file. It works in conjunction with | ||||||||||||||||||||||||||||
| 50 | #$ALLOWED_CODE_OPS_IN_CONFIG_FILE, which if defined restricts the | ||||||||||||||||||||||||||||
| 51 | #opcodes which can be executed using the 'Safe' module. | ||||||||||||||||||||||||||||
| 52 | #setting this to a false value disables code execution in the | ||||||||||||||||||||||||||||
| 53 | #config file | ||||||||||||||||||||||||||||
| 54 | 54 | our $ALLOW_CODE_IN_CONFIG_FILE = 1; | |||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | #arrays in a log message will be joined using this character, | ||||||||||||||||||||||||||||
| 57 | #see Log::Log4perl::Appender::DBI | ||||||||||||||||||||||||||||
| 58 | 54 | our $JOIN_MSG_ARRAY_CHAR = ''; | |||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | #version required for XML::DOM, to enable XML Config parsing | ||||||||||||||||||||||||||||
| 61 | #and XML Config unit tests | ||||||||||||||||||||||||||||
| 62 | 54 | our $DOM_VERSION_REQUIRED = '1.29'; | |||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 54 | our $CHATTY_DESTROY_METHODS = 0; | |||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 54 | our $LOGDIE_MESSAGE_ON_STDERR = 1; | |||||||||||||||||||||||||||
| 67 | 54 | our $LOGEXIT_CODE = 1; | |||||||||||||||||||||||||||
| 68 | 54 | our %IMPORT_CALLED; | |||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 54 | our $EASY_CLOSURES = {}; | |||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | # to throw refs as exceptions via logcarp/confess, turn this off | ||||||||||||||||||||||||||||
| 73 | 54 | our $STRINGIFY_DIE_MESSAGE = 1; | |||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 54 | ▶ | use constant _INTERNAL_DEBUG => 0; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | ################################################## | ||||||||||||||||||||||||||||
| 78 | 57 | ▶ | sub import { | ||||||||||||||||||||||||||
|
Subroutine
import: called CC=17 SCAR=45.8
| |||||||||||||||||||||||||||||
| 79 | ################################################## | ||||||||||||||||||||||||||||
| 80 | 57 | my($class) = shift; | |||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 57 | my $caller_pkg = caller(); | |||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 57 | ▶ | return 1 if $IMPORT_CALLED{$caller_pkg}++; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 57 | my(%tags) = map { $_ => 1 } @_; | |||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | # Lazy man's logger | ||||||||||||||||||||||||||||
| 89 | 57 | ▶ | if(exists $tags{':easy'}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | 0 | $tags{':levels'} = 1; | |||||||||||||||||||||||||||
| 91 | 0 | $tags{':nowarn'} = 1; | |||||||||||||||||||||||||||
| 92 | 0 | $tags{'get_logger'} = 1; | |||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 57 | ▶ | if(exists $tags{':no_extra_logdie_message'}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 96 | 0 | $Log::Log4perl::LOGDIE_MESSAGE_ON_STDERR = 0; | |||||||||||||||||||||||||||
| 97 | 0 | delete $tags{':no_extra_logdie_message'}; | |||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 57 | ▶ | if(exists $tags{get_logger}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 101 | # Export get_logger into the calling module's | ||||||||||||||||||||||||||||
| 102 | 54 | ▶ | no strict qw(refs); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 103 | 13 | *{"$caller_pkg\::get_logger"} = *get_logger; | |||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 13 | delete $tags{get_logger}; | |||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 57 | ▶ | if(exists $tags{':levels'}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 109 | # Export log levels ($DEBUG, $INFO etc.) from Log4perl::Level | ||||||||||||||||||||||||||||
| 110 | 4 | for my $key (keys %Log::Log4perl::Level::PRIORITY) { | |||||||||||||||||||||||||||
| 111 | 32 | my $name = "$caller_pkg\::$key"; | |||||||||||||||||||||||||||
| 112 | # Need to split this up in two lines, or CVS will | ||||||||||||||||||||||||||||
| 113 | # mess it up. | ||||||||||||||||||||||||||||
| 114 | my $value = $Log::Log4perl::Level::PRIORITY{ | ||||||||||||||||||||||||||||
| 115 | 32 | $key}; | |||||||||||||||||||||||||||
| 116 | 54 | ▶ | no strict qw(refs); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 117 | 32 | *{"$name"} = \$value; | |||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | 4 | delete $tags{':levels'}; | |||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | # Lazy man's logger | ||||||||||||||||||||||||||||
| 124 | 57 | ▶ | if(exists $tags{':easy'}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 125 | 0 | delete $tags{':easy'}; | |||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | # Define default logger object in caller's package | ||||||||||||||||||||||||||||
| 128 | 0 | my $logger = get_logger("$caller_pkg"); | |||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | # Define DEBUG, INFO, etc. routines in caller's package | ||||||||||||||||||||||||||||
| 131 | 0 | for(qw(TRACE DEBUG INFO WARN ERROR FATAL ALWAYS)) { | |||||||||||||||||||||||||||
| 132 | 0 | my $level = $_; | |||||||||||||||||||||||||||
| 133 | 0 | ▶ | $level = "OFF" if $level eq "ALWAYS"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 134 | 0 | my $lclevel = lc($_); | |||||||||||||||||||||||||||
| 135 | 0 | ▶ | easy_closure_create($caller_pkg, $_, sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 136 | 0 | ▶ | Log::Log4perl::Logger::init_warn() unless | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$Log::Log4perl::Logger::INITIALIZED or $Log::Log4perl::Logger::NON_INIT_WARNED
MC/DC0%0/2
$Log::Log4perl::Logger::INITIALIZED or $Log::Log4perl::Logger::NON_INIT_WARNED
$Log::Log4perl::Logger::INITIALIZED
$Log::Log4perl::Logger::NON_INIT_WARNED
Truth table0%0/3
A or B
A= $Log::Log4perl::Logger::INITIALIZEDB= $Log::Log4perl::Logger::NON_INIT_WARNED
| |||||||||||||||||||||||||||||
| 137 | $Log::Log4perl::Logger::INITIALIZED or | ||||||||||||||||||||||||||||
| 138 | $Log::Log4perl::Logger::NON_INIT_WARNED; | ||||||||||||||||||||||||||||
| 139 | 0 | $logger->{$level}->($logger, @_, $level); | |||||||||||||||||||||||||||
| 140 | 0 | }, $logger); | |||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | # Define LOGCROAK, LOGCLUCK, etc. routines in caller's package | ||||||||||||||||||||||||||||
| 144 | 0 | for(qw(LOGCROAK LOGCLUCK LOGCARP LOGCONFESS)) { | |||||||||||||||||||||||||||
| 145 | 0 | my $method = "Log::Log4perl::Logger::" . lc($_); | |||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | 0 | ▶ | easy_closure_create($caller_pkg, $_, sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 148 | 0 | unshift @_, $logger; | |||||||||||||||||||||||||||
| 149 | 0 | goto &$method; | |||||||||||||||||||||||||||
| 150 | 0 | }, $logger); | |||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | # Define LOGDIE, LOGWARN | ||||||||||||||||||||||||||||
| 154 | 0 | ▶ | easy_closure_create($caller_pkg, "LOGDIE", sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 155 | 0 | ▶ | Log::Log4perl::Logger::init_warn() unless | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$Log::Log4perl::Logger::INITIALIZED or $Log::Log4perl::Logger::NON_INIT_WARNED
MC/DC0%0/2
$Log::Log4perl::Logger::INITIALIZED or $Log::Log4perl::Logger::NON_INIT_WARNED
$Log::Log4perl::Logger::INITIALIZED
$Log::Log4perl::Logger::NON_INIT_WARNED
Truth table0%0/3
A or B
A= $Log::Log4perl::Logger::INITIALIZEDB= $Log::Log4perl::Logger::NON_INIT_WARNED
| |||||||||||||||||||||||||||||
| 156 | $Log::Log4perl::Logger::INITIALIZED or | ||||||||||||||||||||||||||||
| 157 | $Log::Log4perl::Logger::NON_INIT_WARNED; | ||||||||||||||||||||||||||||
| 158 | 0 | $logger->{FATAL}->($logger, @_, "FATAL"); | |||||||||||||||||||||||||||
| 159 | 0 | ▶ | $Log::Log4perl::LOGDIE_MESSAGE_ON_STDERR ? | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 160 | CORE::die(Log::Log4perl::Logger::callerline(join '', @_)) : | ||||||||||||||||||||||||||||
| 161 | exit $Log::Log4perl::LOGEXIT_CODE; | ||||||||||||||||||||||||||||
| 162 | 0 | }, $logger); | |||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | 0 | ▶ | easy_closure_create($caller_pkg, "LOGEXIT", sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 165 | 0 | ▶ | Log::Log4perl::Logger::init_warn() unless | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$Log::Log4perl::Logger::INITIALIZED or $Log::Log4perl::Logger::NON_INIT_WARNED
MC/DC0%0/2
$Log::Log4perl::Logger::INITIALIZED or $Log::Log4perl::Logger::NON_INIT_WARNED
$Log::Log4perl::Logger::INITIALIZED
$Log::Log4perl::Logger::NON_INIT_WARNED
Truth table0%0/3
A or B
A= $Log::Log4perl::Logger::INITIALIZEDB= $Log::Log4perl::Logger::NON_INIT_WARNED
| |||||||||||||||||||||||||||||
| 166 | $Log::Log4perl::Logger::INITIALIZED or | ||||||||||||||||||||||||||||
| 167 | $Log::Log4perl::Logger::NON_INIT_WARNED; | ||||||||||||||||||||||||||||
| 168 | 0 | $logger->{FATAL}->($logger, @_, "FATAL"); | |||||||||||||||||||||||||||
| 169 | 0 | exit $Log::Log4perl::LOGEXIT_CODE; | |||||||||||||||||||||||||||
| 170 | 0 | }, $logger); | |||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | 0 | ▶ | easy_closure_create($caller_pkg, "LOGWARN", sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 173 | 0 | ▶ | Log::Log4perl::Logger::init_warn() unless | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$Log::Log4perl::Logger::INITIALIZED or $Log::Log4perl::Logger::NON_INIT_WARNED
MC/DC0%0/2
$Log::Log4perl::Logger::INITIALIZED or $Log::Log4perl::Logger::NON_INIT_WARNED
$Log::Log4perl::Logger::INITIALIZED
$Log::Log4perl::Logger::NON_INIT_WARNED
Truth table0%0/3
A or B
A= $Log::Log4perl::Logger::INITIALIZEDB= $Log::Log4perl::Logger::NON_INIT_WARNED
| |||||||||||||||||||||||||||||
| 174 | $Log::Log4perl::Logger::INITIALIZED or | ||||||||||||||||||||||||||||
| 175 | $Log::Log4perl::Logger::NON_INIT_WARNED; | ||||||||||||||||||||||||||||
| 176 | 0 | $logger->{WARN}->($logger, @_, "WARN"); | |||||||||||||||||||||||||||
| 177 | 0 | ▶ | CORE::warn(Log::Log4perl::Logger::callerline(join '', @_)) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 178 | if $Log::Log4perl::LOGDIE_MESSAGE_ON_STDERR; | ||||||||||||||||||||||||||||
| 179 | 0 | }, $logger); | |||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | 57 | ▶ | if(exists $tags{':nowarn'}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 183 | 0 | $Log::Log4perl::Logger::NON_INIT_WARNED = 1; | |||||||||||||||||||||||||||
| 184 | 0 | delete $tags{':nowarn'}; | |||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||
| 187 | 57 | ▶ | if(exists $tags{':nostrict'}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 188 | 1 | $Log::Log4perl::Logger::NO_STRICT = 1; | |||||||||||||||||||||||||||
| 189 | 1 | delete $tags{':nostrict'}; | |||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||
| 192 | 57 | ▶ | if(exists $tags{':resurrect'}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 193 | 0 | my $FILTER_MODULE = "Filter::Util::Call"; | |||||||||||||||||||||||||||
| 194 | 0 | ▶ | if(! Log::Log4perl::Util::module_available($FILTER_MODULE)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 195 | 0 | die "$FILTER_MODULE required with :resurrect" . | |||||||||||||||||||||||||||
| 196 | "(install from CPAN)"; | ||||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||
| 198 | 0 | ▶ | eval "require $FILTER_MODULE" or die "Cannot pull in $FILTER_MODULE"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 199 | Filter::Util::Call::filter_add( | ||||||||||||||||||||||||||||
| 200 | 0 | ▶ | sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 201 | 0 | my($status); | |||||||||||||||||||||||||||
| 202 | 0 | ▶ | s/^\s*###l4p// if | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 203 | ($status = Filter::Util::Call::filter_read()) > 0; | ||||||||||||||||||||||||||||
| 204 | 0 | $status; | |||||||||||||||||||||||||||
| 205 | 0 | }); | |||||||||||||||||||||||||||
| 206 | 0 | delete $tags{':resurrect'}; | |||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||
| 209 | 57 | ▶ | if(keys %tags) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 210 | # We received an Option we couldn't understand. | ||||||||||||||||||||||||||||
| 211 | 0 | die "Unknown Option(s): @{[keys %tags]}"; | |||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||
| 215 | ################################################## | ||||||||||||||||||||||||||||
| 216 | 5 | ▶ | sub initialized { | ||||||||||||||||||||||||||
|
Subroutine
initialized: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 217 | ################################################## | ||||||||||||||||||||||||||||
| 218 | 5 | return $Log::Log4perl::Logger::INITIALIZED; | |||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||
| 221 | ################################################## | ||||||||||||||||||||||||||||
| 222 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 223 | ################################################## | ||||||||||||||||||||||||||||
| 224 | 0 | die "THIS CLASS ISN'T FOR DIRECT USE. " . | |||||||||||||||||||||||||||
| 225 | "PLEASE CHECK 'perldoc " . __PACKAGE__ . "'."; | ||||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||
| 228 | ################################################## | ||||||||||||||||||||||||||||
| 229 | 26 | ▶ | sub reset { # Mainly for debugging/testing | ||||||||||||||||||||||||||
|
Subroutine
reset: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 230 | ################################################## | ||||||||||||||||||||||||||||
| 231 | # Delegate this to the logger ... | ||||||||||||||||||||||||||||
| 232 | 26 | return Log::Log4perl::Logger->reset(); | |||||||||||||||||||||||||||
| 233 | } | ||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||
| 235 | ################################################## | ||||||||||||||||||||||||||||
| 236 | 3 | ▶ | sub init_once { # Call init only if it hasn't been | ||||||||||||||||||||||||||
|
Subroutine
init_once: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 237 | # called yet. | ||||||||||||||||||||||||||||
| 238 | ################################################## | ||||||||||||||||||||||||||||
| 239 | 3 | ▶ | init(@_) unless $Log::Log4perl::Logger::INITIALIZED; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||
| 242 | ################################################## | ||||||||||||||||||||||||||||
| 243 | 158 | ▶ | sub init { # Read the config file | ||||||||||||||||||||||||||
|
Subroutine
init: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 244 | ################################################## | ||||||||||||||||||||||||||||
| 245 | 158 | my($class, @args) = @_; | |||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||
| 247 | #woops, they called ::init instead of ->init, let's be forgiving | ||||||||||||||||||||||||||||
| 248 | 158 | ▶ | if ($class ne __PACKAGE__) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 249 | 60 | unshift(@args, $class); | |||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||
| 252 | # Delegate this to the config module | ||||||||||||||||||||||||||||
| 253 | 158 | return Log::Log4perl::Config->init(@args); | |||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||
| 256 | ################################################## | ||||||||||||||||||||||||||||
| 257 | 5 | ▶ | sub init_and_watch { | ||||||||||||||||||||||||||
|
Subroutine
init_and_watch: called CC=2 SCAR=7.6
Pod
undocumented
| |||||||||||||||||||||||||||||
| 258 | ################################################## | ||||||||||||||||||||||||||||
| 259 | 5 | my($class, @args) = @_; | |||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||
| 261 | #woops, they called ::init instead of ->init, let's be forgiving | ||||||||||||||||||||||||||||
| 262 | 5 | ▶ | if ($class ne __PACKAGE__) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 263 | 0 | unshift(@args, $class); | |||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||
| 266 | # Delegate this to the config module | ||||||||||||||||||||||||||||
| 267 | 5 | return Log::Log4perl::Config->init_and_watch(@args); | |||||||||||||||||||||||||||
| 268 | } | ||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||
| 271 | ################################################## | ||||||||||||||||||||||||||||
| 272 | 0 | ▶ | sub easy_init { # Initialize the root logger with a screen appender | ||||||||||||||||||||||||||
|
Subroutine
easy_init: not called CC=12 SCAR=50.5
Pod
undocumented
| |||||||||||||||||||||||||||||
| 273 | ################################################## | ||||||||||||||||||||||||||||
| 274 | 0 | my($class, @args) = @_; | |||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||
| 276 | # Did somebody call us with Log::Log4perl::easy_init()? | ||||||||||||||||||||||||||||
| 277 | 0 | ▶ | if(ref($class) or $class =~ /^\d+$/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $class or $class =~ /^\d+$/
MC/DC0%0/2
ref $class or $class =~ /^\d+$/
ref $class
$class =~ /^\d+$/
Truth table0%0/3
A or B
A= ref $classB= $class =~ /^\d+$/
| |||||||||||||||||||||||||||||
| 278 | 0 | unshift @args, $class; | |||||||||||||||||||||||||||
| 279 | } | ||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||
| 281 | # Reset everything first | ||||||||||||||||||||||||||||
| 282 | 0 | Log::Log4perl->reset(); | |||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||
| 284 | 0 | my @loggers = (); | |||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||
| 286 | 0 | my %default = ( level => $DEBUG, | |||||||||||||||||||||||||||
| 287 | file => "STDERR", | ||||||||||||||||||||||||||||
| 288 | utf8 => undef, | ||||||||||||||||||||||||||||
| 289 | category => "", | ||||||||||||||||||||||||||||
| 290 | layout => "%d %m%n", | ||||||||||||||||||||||||||||
| 291 | ); | ||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||
| 293 | 0 | ▶ | if(!@args) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 294 | 0 | push @loggers, \%default; | |||||||||||||||||||||||||||
| 295 | } else { | ||||||||||||||||||||||||||||
| 296 | 0 | for my $arg (@args) { | |||||||||||||||||||||||||||
| 297 | 0 | ▶ | if($arg =~ /^\d+$/) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 298 | 0 | my %logger = (%default, level => $arg); | |||||||||||||||||||||||||||
| 299 | 0 | push @loggers, \%logger; | |||||||||||||||||||||||||||
| 300 | } elsif(ref($arg) eq "HASH") { | ||||||||||||||||||||||||||||
| 301 | 0 | my %logger = (%default, %$arg); | |||||||||||||||||||||||||||
| 302 | 0 | push @loggers, \%logger; | |||||||||||||||||||||||||||
| 303 | } else { | ||||||||||||||||||||||||||||
| 304 | # I suggest this becomes a croak() after a | ||||||||||||||||||||||||||||
| 305 | # reasonable deprecation cycle. | ||||||||||||||||||||||||||||
| 306 | 0 | carp "All arguments to easy_init should be either " | |||||||||||||||||||||||||||
| 307 | . "an integer log level or a hash reference."; | ||||||||||||||||||||||||||||
| 308 | } | ||||||||||||||||||||||||||||
| 309 | } | ||||||||||||||||||||||||||||
| 310 | } | ||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||
| 312 | 0 | for my $logger (@loggers) { | |||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||
| 314 | 0 | my $app; | |||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||
| 316 | 0 | ▶ | if($logger->{file} =~ /^stderr$/i) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 317 | $app = Log::Log4perl::Appender->new( | ||||||||||||||||||||||||||||
| 318 | "Log::Log4perl::Appender::Screen", | ||||||||||||||||||||||||||||
| 319 | 0 | utf8 => $logger->{utf8}); | |||||||||||||||||||||||||||
| 320 | } elsif($logger->{file} =~ /^stdout$/i) { | ||||||||||||||||||||||||||||
| 321 | $app = Log::Log4perl::Appender->new( | ||||||||||||||||||||||||||||
| 322 | "Log::Log4perl::Appender::Screen", | ||||||||||||||||||||||||||||
| 323 | stderr => 0, | ||||||||||||||||||||||||||||
| 324 | 0 | utf8 => $logger->{utf8}); | |||||||||||||||||||||||||||
| 325 | } else { | ||||||||||||||||||||||||||||
| 326 | 0 | my $binmode; | |||||||||||||||||||||||||||
| 327 | 0 | ▶ | if($logger->{file} =~ s/^(:.*?)>/>/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 328 | 0 | $binmode = $1; | |||||||||||||||||||||||||||
| 329 | } | ||||||||||||||||||||||||||||
| 330 | 0 | $logger->{file} =~ /^(>)?(>)?/; | |||||||||||||||||||||||||||
| 331 | 0 | ▶ | my $mode = ($2 ? "append" : "write"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 332 | 0 | $logger->{file} =~ s/.*>+\s*//g; | |||||||||||||||||||||||||||
| 333 | $app = Log::Log4perl::Appender->new( | ||||||||||||||||||||||||||||
| 334 | "Log::Log4perl::Appender::File", | ||||||||||||||||||||||||||||
| 335 | filename => $logger->{file}, | ||||||||||||||||||||||||||||
| 336 | mode => $mode, | ||||||||||||||||||||||||||||
| 337 | utf8 => $logger->{utf8}, | ||||||||||||||||||||||||||||
| 338 | 0 | binmode => $binmode, | |||||||||||||||||||||||||||
| 339 | ); | ||||||||||||||||||||||||||||
| 340 | } | ||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||
| 342 | my $layout = Log::Log4perl::Layout::PatternLayout->new( | ||||||||||||||||||||||||||||
| 343 | 0 | $logger->{layout}); | |||||||||||||||||||||||||||
| 344 | 0 | $app->layout($layout); | |||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||
| 346 | 0 | my $log = Log::Log4perl->get_logger($logger->{category}); | |||||||||||||||||||||||||||
| 347 | 0 | $log->level($logger->{level}); | |||||||||||||||||||||||||||
| 348 | 0 | $log->add_appender($app); | |||||||||||||||||||||||||||
| 349 | } | ||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||
| 351 | 0 | $Log::Log4perl::Logger::INITIALIZED = 1; | |||||||||||||||||||||||||||
| 352 | } | ||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||
| 354 | ################################################## | ||||||||||||||||||||||||||||
| 355 | 3 | ▶ | sub wrapper_register { | ||||||||||||||||||||||||||
|
Subroutine
wrapper_register: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 356 | ################################################## | ||||||||||||||||||||||||||||
| 357 | 3 | my $wrapper = $_[-1]; | |||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||
| 359 | 3 | $WRAPPERS_REGISTERED{ $wrapper } = 1; | |||||||||||||||||||||||||||
| 360 | } | ||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||
| 362 | ################################################## | ||||||||||||||||||||||||||||
| 363 | 179 | ▶ | sub get_logger { # Get an instance (shortcut) | ||||||||||||||||||||||||||
|
Subroutine
get_logger: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 364 | ################################################## | ||||||||||||||||||||||||||||
| 365 | # get_logger() can be called in the following ways: | ||||||||||||||||||||||||||||
| 366 | # | ||||||||||||||||||||||||||||
| 367 | # (1) Log::Log4perl::get_logger() => () | ||||||||||||||||||||||||||||
| 368 | # (2) Log::Log4perl->get_logger() => ("Log::Log4perl") | ||||||||||||||||||||||||||||
| 369 | # (3) Log::Log4perl::get_logger($cat) => ($cat) | ||||||||||||||||||||||||||||
| 370 | # | ||||||||||||||||||||||||||||
| 371 | # (5) Log::Log4perl->get_logger($cat) => ("Log::Log4perl", $cat) | ||||||||||||||||||||||||||||
| 372 | # (6) L4pSubclass->get_logger($cat) => ("L4pSubclass", $cat) | ||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||
| 374 | # Note that (4) L4pSubclass->get_logger() => ("L4pSubclass") | ||||||||||||||||||||||||||||
| 375 | # is indistinguishable from (3) and therefore can't be allowed. | ||||||||||||||||||||||||||||
| 376 | # Wrapper classes always have to specify the category explicitly. | ||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||
| 378 | 179 | my $category; | |||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||
| 380 | 179 | ▶ | if(@_ == 0) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 381 | # 1 | ||||||||||||||||||||||||||||
| 382 | 14 | my $level = 0; | |||||||||||||||||||||||||||
| 383 | 15 | do { $category = scalar caller($level++); | |||||||||||||||||||||||||||
| 384 | 14 | ▶ | } while exists $WRAPPERS_REGISTERED{ $category }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||
| 386 | } elsif(@_ == 1) { | ||||||||||||||||||||||||||||
| 387 | # 2, 3 | ||||||||||||||||||||||||||||
| 388 | 77 | $category = $_[0]; | |||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||
| 390 | 77 | my $level = 0; | |||||||||||||||||||||||||||
| 391 | 77 | ▶ | while(exists $WRAPPERS_REGISTERED{ $category }) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 392 | 7 | $category = scalar caller($level++); | |||||||||||||||||||||||||||
| 393 | } | ||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||
| 395 | } else { | ||||||||||||||||||||||||||||
| 396 | # 5, 6 | ||||||||||||||||||||||||||||
| 397 | 88 | $category = $_[1]; | |||||||||||||||||||||||||||
| 398 | } | ||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||
| 400 | # Delegate this to the logger module | ||||||||||||||||||||||||||||
| 401 | 179 | return Log::Log4perl::Logger->get_logger($category); | |||||||||||||||||||||||||||
| 402 | } | ||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||
| 404 | ########################################### | ||||||||||||||||||||||||||||
| 405 | 205 | ▶ | sub caller_depth_offset { | ||||||||||||||||||||||||||
|
Subroutine
caller_depth_offset: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 406 | ########################################### | ||||||||||||||||||||||||||||
| 407 | 205 | my( $level ) = @_; | |||||||||||||||||||||||||||
| 408 | |||||||||||||||||||||||||||||
| 409 | 205 | my $category; | |||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||
| 411 | { | ||||||||||||||||||||||||||||
| 412 | 205 | my $category = scalar caller($level + 1); | |||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||
| 414 | 206 | ▶ | if(defined $category and | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $category and exists $Log::Log4perl::WRAPPERS_REGISTERED{$category}
MC/DC100%2/2
defined $category and exists $Log::Log4perl::WRAPPERS_REGISTERED{$category}
defined $category
exists $Log::Log4perl::WRAPPERS_REGISTERED{$category}
Truth table100%3/3
A and B
A= defined $categoryB= exists $Log::Log4perl::WRAPPERS_REGISTERED{$category}
| |||||||||||||||||||||||||||||
| 415 | exists $WRAPPERS_REGISTERED{ $category }) { | ||||||||||||||||||||||||||||
| 416 | 1 | $level++; | |||||||||||||||||||||||||||
| 417 | 1 | redo; | |||||||||||||||||||||||||||
| 418 | } | ||||||||||||||||||||||||||||
| 419 | } | ||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||
| 421 | 205 | return $level; | |||||||||||||||||||||||||||
| 422 | } | ||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||
| 424 | ################################################## | ||||||||||||||||||||||||||||
| 425 | 37 | ▶ | sub appenders { # Get a hashref of all defined appender wrappers | ||||||||||||||||||||||||||
|
Subroutine
appenders: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 426 | ################################################## | ||||||||||||||||||||||||||||
| 427 | 37 | return \%Log::Log4perl::Logger::APPENDER_BY_NAME; | |||||||||||||||||||||||||||
| 428 | } | ||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||
| 430 | ################################################## | ||||||||||||||||||||||||||||
| 431 | 3 | ▶ | sub add_appender { # Add an appender to the system, but don't assign | ||||||||||||||||||||||||||
|
Subroutine
add_appender: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 432 | # it to a logger yet | ||||||||||||||||||||||||||||
| 433 | ################################################## | ||||||||||||||||||||||||||||
| 434 | 3 | my($class, $appender) = @_; | |||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||
| 436 | 3 | my $name = $appender->name(); | |||||||||||||||||||||||||||
| 437 | 3 | ▶ | die "Mandatory parameter 'name' missing in appender" unless defined $name; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||
| 439 | # Make it known by name in the Log4perl universe | ||||||||||||||||||||||||||||
| 440 | # (so that composite appenders can find it) | ||||||||||||||||||||||||||||
| 441 | 3 | Log::Log4perl->appenders()->{ $name } = $appender; | |||||||||||||||||||||||||||
| 442 | } | ||||||||||||||||||||||||||||
| 443 | |||||||||||||||||||||||||||||
| 444 | ################################################## | ||||||||||||||||||||||||||||
| 445 | # Return number of appenders changed | ||||||||||||||||||||||||||||
| 446 | 4 | ▶ | sub appender_thresholds_adjust { # Readjust appender thresholds | ||||||||||||||||||||||||||
|
Subroutine
appender_thresholds_adjust: called CC=9 SCAR=22.5
Pod
undocumented
| |||||||||||||||||||||||||||||
| 447 | ################################################## | ||||||||||||||||||||||||||||
| 448 | # If someone calls L4p-> and not L4p:: | ||||||||||||||||||||||||||||
| 449 | 4 | ▶ | shift if $_[0] eq __PACKAGE__; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 450 | 4 | my($delta, $appenders) = @_; | |||||||||||||||||||||||||||
| 451 | 4 | my $retval = 0; | |||||||||||||||||||||||||||
| 452 | |||||||||||||||||||||||||||||
| 453 | 4 | ▶ | if($delta == 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 454 | # Nothing to do, no delta given. | ||||||||||||||||||||||||||||
| 455 | 0 | return; | |||||||||||||||||||||||||||
| 456 | } | ||||||||||||||||||||||||||||
| 457 | |||||||||||||||||||||||||||||
| 458 | 4 | ▶ | if(defined $appenders) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 459 | # Map names to objects | ||||||||||||||||||||||||||||
| 460 | $appenders = [map { | ||||||||||||||||||||||||||||
| 461 | 1 | die "Unkown appender: '$_'" unless exists | |||||||||||||||||||||||||||
| 462 | $Log::Log4perl::Logger::APPENDER_BY_NAME{ | ||||||||||||||||||||||||||||
| 463 | 1 | ▶ | $_}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 464 | $Log::Log4perl::Logger::APPENDER_BY_NAME{ | ||||||||||||||||||||||||||||
| 465 | 1 | $_} | |||||||||||||||||||||||||||
| 466 | } @$appenders]; | ||||||||||||||||||||||||||||
| 467 | } else { | ||||||||||||||||||||||||||||
| 468 | # Just hand over all known appenders | ||||||||||||||||||||||||||||
| 469 | 3 | ▶ | $appenders = [values %{Log::Log4perl::appenders()}] unless | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 470 | defined $appenders; | ||||||||||||||||||||||||||||
| 471 | } | ||||||||||||||||||||||||||||
| 472 | |||||||||||||||||||||||||||||
| 473 | # Change all appender thresholds; | ||||||||||||||||||||||||||||
| 474 | 4 | foreach my $app (@$appenders) { | |||||||||||||||||||||||||||
| 475 | 5 | my $old_thres = $app->threshold(); | |||||||||||||||||||||||||||
| 476 | 5 | my $new_thres; | |||||||||||||||||||||||||||
| 477 | 5 | ▶ | if($delta > 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 478 | 2 | $new_thres = Log::Log4perl::Level::get_higher_level( | |||||||||||||||||||||||||||
| 479 | $old_thres, $delta); | ||||||||||||||||||||||||||||
| 480 | } else { | ||||||||||||||||||||||||||||
| 481 | 3 | $new_thres = Log::Log4perl::Level::get_lower_level( | |||||||||||||||||||||||||||
| 482 | $old_thres, -$delta); | ||||||||||||||||||||||||||||
| 483 | } | ||||||||||||||||||||||||||||
| 484 | |||||||||||||||||||||||||||||
| 485 | 5 | ▶ | ++$retval if ($app->threshold($new_thres) == $new_thres); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 486 | } | ||||||||||||||||||||||||||||
| 487 | 4 | return $retval; | |||||||||||||||||||||||||||
| 488 | } | ||||||||||||||||||||||||||||
| 489 | |||||||||||||||||||||||||||||
| 490 | ################################################## | ||||||||||||||||||||||||||||
| 491 | 1 | ▶ | sub appender_by_name { # Get a (real) appender by name | ||||||||||||||||||||||||||
|
Subroutine
appender_by_name: called CC=4 SCAR=16.4
Pod
undocumented
| |||||||||||||||||||||||||||||
| 492 | ################################################## | ||||||||||||||||||||||||||||
| 493 | # If someone calls L4p->appender_by_name and not L4p::appender_by_name | ||||||||||||||||||||||||||||
| 494 | 1 | ▶ | shift if $_[0] eq __PACKAGE__; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 495 | |||||||||||||||||||||||||||||
| 496 | 1 | my($name) = @_; | |||||||||||||||||||||||||||
| 497 | |||||||||||||||||||||||||||||
| 498 | 1 | ▶ | if(defined $name and | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $name and exists $Log::Log4perl::Logger::APPENDER_BY_NAME{$name}
MC/DC0%0/2
defined $name and exists $Log::Log4perl::Logger::APPENDER_BY_NAME{$name}
defined $name
exists $Log::Log4perl::Logger::APPENDER_BY_NAME{$name}
Truth table33%1/3
A and B
A= defined $nameB= exists $Log::Log4perl::Logger::APPENDER_BY_NAME{$name}
| |||||||||||||||||||||||||||||
| 499 | exists $Log::Log4perl::Logger::APPENDER_BY_NAME{ | ||||||||||||||||||||||||||||
| 500 | $name}) { | ||||||||||||||||||||||||||||
| 501 | return $Log::Log4perl::Logger::APPENDER_BY_NAME{ | ||||||||||||||||||||||||||||
| 502 | 1 | $name}->{appender}; | |||||||||||||||||||||||||||
| 503 | } else { | ||||||||||||||||||||||||||||
| 504 | 0 | return undef; | |||||||||||||||||||||||||||
| 505 | } | ||||||||||||||||||||||||||||
| 506 | } | ||||||||||||||||||||||||||||
| 507 | |||||||||||||||||||||||||||||
| 508 | ################################################## | ||||||||||||||||||||||||||||
| 509 | 1 | ▶ | sub eradicate_appender { # Remove an appender from the system | ||||||||||||||||||||||||||
|
Subroutine
eradicate_appender: called CC=2 SCAR=7.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 510 | ################################################## | ||||||||||||||||||||||||||||
| 511 | # If someone calls L4p->... and not L4p::... | ||||||||||||||||||||||||||||
| 512 | 1 | ▶ | shift if $_[0] eq __PACKAGE__; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 513 | 1 | Log::Log4perl::Logger->eradicate_appender(@_); | |||||||||||||||||||||||||||
| 514 | } | ||||||||||||||||||||||||||||
| 515 | |||||||||||||||||||||||||||||
| 516 | ################################################## | ||||||||||||||||||||||||||||
| 517 | 0 | ▶ | sub infiltrate_lwp { # | ||||||||||||||||||||||||||
|
Subroutine
infiltrate_lwp: not called CC=1 SCAR=3.3
Pod
documented
| |||||||||||||||||||||||||||||
| 518 | ################################################## | ||||||||||||||||||||||||||||
| 519 | 54 | ▶ | no warnings qw(redefine); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 520 | |||||||||||||||||||||||||||||
| 521 | 0 | ▶ | my $l4p_wrapper = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 522 | 0 | my($prio, @message) = @_; | |||||||||||||||||||||||||||
| 523 | 0 | local $Log::Log4perl::caller_depth = | |||||||||||||||||||||||||||
| 524 | $Log::Log4perl::caller_depth + 2; | ||||||||||||||||||||||||||||
| 525 | 0 | get_logger(scalar caller(1))->log($prio, @message); | |||||||||||||||||||||||||||
| 526 | 0 | }; | |||||||||||||||||||||||||||
| 527 | |||||||||||||||||||||||||||||
| 528 | 0 | ▶ | *LWP::Debug::trace = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 529 | 0 | $l4p_wrapper->($INFO, @_); | |||||||||||||||||||||||||||
| 530 | 0 | }; | |||||||||||||||||||||||||||
| 531 | *LWP::Debug::conns = | ||||||||||||||||||||||||||||
| 532 | 0 | ▶ | *LWP::Debug::debug = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 533 | 0 | $l4p_wrapper->($DEBUG, @_); | |||||||||||||||||||||||||||
| 534 | 0 | }; | |||||||||||||||||||||||||||
| 535 | } | ||||||||||||||||||||||||||||
| 536 | |||||||||||||||||||||||||||||
| 537 | ################################################## | ||||||||||||||||||||||||||||
| 538 | 0 | ▶ | sub easy_closure_create { | ||||||||||||||||||||||||||
|
Subroutine
easy_closure_create: not called CC=1 SCAR=2.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 539 | ################################################## | ||||||||||||||||||||||||||||
| 540 | 0 | my($caller_pkg, $entry, $code, $logger) = @_; | |||||||||||||||||||||||||||
| 541 | |||||||||||||||||||||||||||||
| 542 | 54 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 543 | |||||||||||||||||||||||||||||
| 544 | 0 | print("easy_closure: Setting shortcut $caller_pkg\::$entry ", | |||||||||||||||||||||||||||
| 545 | "(logger=$logger\n") if _INTERNAL_DEBUG; | ||||||||||||||||||||||||||||
| 546 | |||||||||||||||||||||||||||||
| 547 | 0 | $EASY_CLOSURES->{ $caller_pkg }->{ $entry } = $logger; | |||||||||||||||||||||||||||
| 548 | 0 | *{"$caller_pkg\::$entry"} = $code; | |||||||||||||||||||||||||||
| 549 | } | ||||||||||||||||||||||||||||
| 550 | |||||||||||||||||||||||||||||
| 551 | ########################################### | ||||||||||||||||||||||||||||
| 552 | 0 | ▶ | sub easy_closure_cleanup { | ||||||||||||||||||||||||||
|
Subroutine
easy_closure_cleanup: not called CC=1 SCAR=1.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 553 | ########################################### | ||||||||||||||||||||||||||||
| 554 | 0 | my($caller_pkg, $entry) = @_; | |||||||||||||||||||||||||||
| 555 | |||||||||||||||||||||||||||||
| 556 | 54 | ▶ | no warnings 'redefine'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 557 | 54 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 558 | |||||||||||||||||||||||||||||
| 559 | 0 | my $logger = $EASY_CLOSURES->{ $caller_pkg }->{ $entry }; | |||||||||||||||||||||||||||
| 560 | |||||||||||||||||||||||||||||
| 561 | 0 | print("easy_closure: Nuking easy shortcut $caller_pkg\::$entry ", | |||||||||||||||||||||||||||
| 562 | "(logger=$logger\n") if _INTERNAL_DEBUG; | ||||||||||||||||||||||||||||
| 563 | |||||||||||||||||||||||||||||
| 564 | 0 | ▶ | *{"$caller_pkg\::$entry"} = sub { }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 565 | 0 | delete $EASY_CLOSURES->{ $caller_pkg }->{ $entry }; | |||||||||||||||||||||||||||
| 566 | } | ||||||||||||||||||||||||||||
| 567 | |||||||||||||||||||||||||||||
| 568 | ################################################## | ||||||||||||||||||||||||||||
| 569 | 0 | ▶ | sub easy_closure_category_cleanup { | ||||||||||||||||||||||||||
|
Subroutine
easy_closure_category_cleanup: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 570 | ################################################## | ||||||||||||||||||||||||||||
| 571 | 0 | my($caller_pkg) = @_; | |||||||||||||||||||||||||||
| 572 | |||||||||||||||||||||||||||||
| 573 | 0 | ▶ | if(! exists $EASY_CLOSURES->{ $caller_pkg } ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 574 | 0 | return 1; | |||||||||||||||||||||||||||
| 575 | } | ||||||||||||||||||||||||||||
| 576 | |||||||||||||||||||||||||||||
| 577 | 0 | for my $entry ( keys %{ $EASY_CLOSURES->{ $caller_pkg } } ) { | |||||||||||||||||||||||||||
| 578 | 0 | easy_closure_cleanup( $caller_pkg, $entry ); | |||||||||||||||||||||||||||
| 579 | } | ||||||||||||||||||||||||||||
| 580 | |||||||||||||||||||||||||||||
| 581 | 0 | delete $EASY_CLOSURES->{ $caller_pkg }; | |||||||||||||||||||||||||||
| 582 | } | ||||||||||||||||||||||||||||
| 583 | |||||||||||||||||||||||||||||
| 584 | ########################################### | ||||||||||||||||||||||||||||
| 585 | 55 | ▶ | sub easy_closure_global_cleanup { | ||||||||||||||||||||||||||
|
Subroutine
easy_closure_global_cleanup: called CC=2 SCAR=9.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 586 | ########################################### | ||||||||||||||||||||||||||||
| 587 | |||||||||||||||||||||||||||||
| 588 | 55 | for my $caller_pkg ( keys %$EASY_CLOSURES ) { | |||||||||||||||||||||||||||
| 589 | 0 | easy_closure_category_cleanup( $caller_pkg ); | |||||||||||||||||||||||||||
| 590 | } | ||||||||||||||||||||||||||||
| 591 | } | ||||||||||||||||||||||||||||
| 592 | |||||||||||||||||||||||||||||
| 593 | ########################################### | ||||||||||||||||||||||||||||
| 594 | 0 | ▶ | sub easy_closure_logger_remove { | ||||||||||||||||||||||||||
|
Subroutine
easy_closure_logger_remove: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 595 | ########################################### | ||||||||||||||||||||||||||||
| 596 | 0 | my($class, $logger) = @_; | |||||||||||||||||||||||||||
| 597 | |||||||||||||||||||||||||||||
| 598 | 0 | PKG: for my $caller_pkg ( keys %$EASY_CLOSURES ) { | |||||||||||||||||||||||||||
| 599 | 0 | for my $entry ( keys %{ $EASY_CLOSURES->{ $caller_pkg } } ) { | |||||||||||||||||||||||||||
| 600 | 0 | ▶ | if( $logger == $EASY_CLOSURES->{ $caller_pkg }->{ $entry } ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 601 | 0 | easy_closure_category_cleanup( $caller_pkg ); | |||||||||||||||||||||||||||
| 602 | 0 | next PKG; | |||||||||||||||||||||||||||
| 603 | } | ||||||||||||||||||||||||||||
| 604 | } | ||||||||||||||||||||||||||||
| 605 | } | ||||||||||||||||||||||||||||
| 606 | } | ||||||||||||||||||||||||||||
| 607 | |||||||||||||||||||||||||||||
| 608 | ################################################## | ||||||||||||||||||||||||||||
| 609 | 0 | ▶ | sub remove_logger { | ||||||||||||||||||||||||||
|
Subroutine
remove_logger: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 610 | ################################################## | ||||||||||||||||||||||||||||
| 611 | 0 | my ($class, $logger) = @_; | |||||||||||||||||||||||||||
| 612 | |||||||||||||||||||||||||||||
| 613 | # Any stealth logger convenience function still using it will | ||||||||||||||||||||||||||||
| 614 | # now become a no-op. | ||||||||||||||||||||||||||||
| 615 | 0 | Log::Log4perl->easy_closure_logger_remove( $logger ); | |||||||||||||||||||||||||||
| 616 | |||||||||||||||||||||||||||||
| 617 | # Remove the logger from the system | ||||||||||||||||||||||||||||
| 618 | # Need to split this up in two lines, or CVS will | ||||||||||||||||||||||||||||
| 619 | # mess it up. | ||||||||||||||||||||||||||||
| 620 | delete $Log::Log4perl::Logger::LOGGERS_BY_NAME->{ | ||||||||||||||||||||||||||||
| 621 | 0 | $logger->{category} }; | |||||||||||||||||||||||||||
| 622 | } | ||||||||||||||||||||||||||||
| 623 | |||||||||||||||||||||||||||||
| 624 | 54 | 1; | |||||||||||||||||||||||||||
| 625 | |||||||||||||||||||||||||||||
| 626 | __END__ | ||||||||||||||||||||||||||||