| 1 | ################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 2 | package Log::Log4perl::Config; | ||||||||||||||||||||||||||||||||||||||||||
| 3 | ################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 4 | 54 | ▶ | use 5.006; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 54 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 54 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 54 | ▶ | use Log::Log4perl::Logger; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 54 | ▶ | use Log::Log4perl::Level; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 54 | ▶ | use Log::Log4perl::Config::PropertyConfigurator; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 54 | ▶ | use Log::Log4perl::JavaMap; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 54 | ▶ | use Log::Log4perl::Filter; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 54 | ▶ | use Log::Log4perl::Filter::Boolean; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 54 | ▶ | use Log::Log4perl::Config::Watch; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | 54 | ▶ | use constant _INTERNAL_DEBUG => 0; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | 54 | our $CONFIG_FILE_READS = 0; | |||||||||||||||||||||||||||||||||||||||||
| 19 | 54 | our $CONFIG_INTEGRITY_CHECK = 1; | |||||||||||||||||||||||||||||||||||||||||
| 20 | 54 | our $CONFIG_INTEGRITY_ERROR = undef; | |||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | 54 | our $WATCHER; | |||||||||||||||||||||||||||||||||||||||||
| 23 | 54 | our $DEFAULT_WATCH_DELAY = 60; # seconds | |||||||||||||||||||||||||||||||||||||||||
| 24 | 54 | our $OPTS = {}; | |||||||||||||||||||||||||||||||||||||||||
| 25 | 54 | our $OLD_CONFIG; | |||||||||||||||||||||||||||||||||||||||||
| 26 | 54 | our $LOGGERS_DEFINED; | |||||||||||||||||||||||||||||||||||||||||
| 27 | 54 | our $UTF8 = 0; | |||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | ########################################### | ||||||||||||||||||||||||||||||||||||||||||
| 30 | 158 | ▶ | sub init { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
init: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | ########################################### | ||||||||||||||||||||||||||||||||||||||||||
| 32 | 158 | Log::Log4perl::Logger->reset(); | |||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | 158 | undef $WATCHER; # just in case there's a one left over (e.g. test cases) | |||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | 158 | return _init(@_); | |||||||||||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | ########################################### | ||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | ▶ | sub utf8 { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
utf8: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 41 | ########################################### | ||||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | my( $class, $flag ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | ▶ | $UTF8 = $flag if defined $flag; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | return $UTF8; | |||||||||||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||
| 49 | ########################################### | ||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | ▶ | sub watcher { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
watcher: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | ########################################### | ||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | return $WATCHER; | |||||||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | ########################################### | ||||||||||||||||||||||||||||||||||||||||||
| 56 | 5 | ▶ | sub init_and_watch { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
init_and_watch: called CC=11 SCAR=28.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | ########################################### | ||||||||||||||||||||||||||||||||||||||||||
| 58 | 5 | my ($class, $config, $delay, $opts) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 59 | # delay can be a signal name - in this case we're gonna | ||||||||||||||||||||||||||||||||||||||||||
| 60 | # set up a signal handler. | ||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||
| 62 | 5 | ▶ | if(defined $WATCHER) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 63 | 3 | $config = $WATCHER->file(); | |||||||||||||||||||||||||||||||||||||||||
| 64 | 3 | ▶ | if(defined $Log::Log4perl::Config::Watch::SIGNAL_CAUGHT) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 65 | 1 | $delay = $WATCHER->signal(); | |||||||||||||||||||||||||||||||||||||||||
| 66 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 67 | 2 | $delay = $WATCHER->check_interval(); | |||||||||||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | 5 | print "init_and_watch ($config-$delay). Resetting.\n" if _INTERNAL_DEBUG; | |||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||
| 73 | 5 | Log::Log4perl::Logger->reset(); | |||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | 5 | ▶ | defined ($delay) or $delay = $DEFAULT_WATCH_DELAY; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||
| 77 | 5 | ▶ | if (ref $config) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | die "Log4perl can only watch a file, not a string of " . | |||||||||||||||||||||||||||||||||||||||||
| 79 | "configuration information"; | ||||||||||||||||||||||||||||||||||||||||||
| 80 | }elsif ($config =~ m!^(https?|ftp|wais|gopher|file):!){ | ||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | die "Log4perl can only watch a file, not a url like $config"; | |||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | 5 | ▶ | if($delay =~ /\D/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 85 | 2 | $WATCHER = Log::Log4perl::Config::Watch->new( | |||||||||||||||||||||||||||||||||||||||||
| 86 | file => $config, | ||||||||||||||||||||||||||||||||||||||||||
| 87 | signal => $delay, | ||||||||||||||||||||||||||||||||||||||||||
| 88 | l4p_internal => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 89 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 90 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 91 | 3 | $WATCHER = Log::Log4perl::Config::Watch->new( | |||||||||||||||||||||||||||||||||||||||||
| 92 | file => $config, | ||||||||||||||||||||||||||||||||||||||||||
| 93 | check_interval => $delay, | ||||||||||||||||||||||||||||||||||||||||||
| 94 | l4p_internal => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 95 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||
| 98 | 5 | ▶ | if(defined $opts) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | ▶ | die "Parameter $opts needs to be a hash ref" if ref($opts) ne "HASH"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | $OPTS = $opts; | |||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||
| 103 | 5 | eval { _init($class, $config); }; | |||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||
| 105 | 5 | ▶ | if($@) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | ▶ | die "$@" unless defined $OLD_CONFIG; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 107 | # Call _init with a pre-parsed config to go back to old setting | ||||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | _init($class, undef, $OLD_CONFIG); | |||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | warn "Loading new config failed, reverted to old one\n"; | |||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||
| 113 | ################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 114 | 163 | ▶ | sub _init { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_init: called CC=29 SCAR=33.7
| |||||||||||||||||||||||||||||||||||||||||||
| 115 | ################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 116 | 163 | my($class, $config, $data) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||
| 118 | 163 | my %additivity = (); | |||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||
| 120 | 163 | $LOGGERS_DEFINED = 0; | |||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||
| 122 | 163 | print "Calling _init\n" if _INTERNAL_DEBUG; | |||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||
| 124 | #keep track so we don't create the same one twice | ||||||||||||||||||||||||||||||||||||||||||
| 125 | 163 | my %appenders_created = (); | |||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||
| 127 | #some appenders need to run certain subroutines right at the | ||||||||||||||||||||||||||||||||||||||||||
| 128 | #end of the configuration phase, when all settings are in place. | ||||||||||||||||||||||||||||||||||||||||||
| 129 | 163 | my @post_config_subs = (); | |||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||
| 131 | # This logic is probably suited to win an obfuscated programming | ||||||||||||||||||||||||||||||||||||||||||
| 132 | # contest. It desperately needs to be rewritten. | ||||||||||||||||||||||||||||||||||||||||||
| 133 | # Basically, it works like this: | ||||||||||||||||||||||||||||||||||||||||||
| 134 | # config_read() reads the entire config file into a hash of hashes: | ||||||||||||||||||||||||||||||||||||||||||
| 135 | # log4j.logger.foo.bar.baz: WARN, A1 | ||||||||||||||||||||||||||||||||||||||||||
| 136 | # gets transformed into | ||||||||||||||||||||||||||||||||||||||||||
| 137 | # $data->{log4j}->{logger}->{foo}->{bar}->{baz} = "WARN, A1"; | ||||||||||||||||||||||||||||||||||||||||||
| 138 | # The code below creates the necessary loggers, sets the appenders | ||||||||||||||||||||||||||||||||||||||||||
| 139 | # and the layouts etc. | ||||||||||||||||||||||||||||||||||||||||||
| 140 | # In order to transform parts of this tree back into identifiers | ||||||||||||||||||||||||||||||||||||||||||
| 141 | # (like "foo.bar.baz"), we're using the leaf_paths functions below. | ||||||||||||||||||||||||||||||||||||||||||
| 142 | # Pretty scary. But it allows the lines of the config file to be | ||||||||||||||||||||||||||||||||||||||||||
| 143 | # in *arbitrary* order. | ||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||
| 145 | 163 | ▶ | $data = config_read($config) unless defined $data; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||
| 147 | 154 | if(_INTERNAL_DEBUG) { | |||||||||||||||||||||||||||||||||||||||||
| 148 | require Data::Dumper; | ||||||||||||||||||||||||||||||||||||||||||
| 149 | Data::Dumper->import(); | ||||||||||||||||||||||||||||||||||||||||||
| 150 | print Data::Dumper::Dumper($data); | ||||||||||||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||
| 153 | 154 | my @loggers = (); | |||||||||||||||||||||||||||||||||||||||||
| 154 | 154 | my %filter_names = (); | |||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||
| 156 | 154 | my $system_wide_threshold; | |||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||
| 158 | # Autocorrect the rootlogger/rootLogger typo | ||||||||||||||||||||||||||||||||||||||||||
| 159 | 154 | ▶ | if(exists $data->{rootlogger} and | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
exists $data->{"rootlogger"} and not exists $data->{"rootLogger"}
MC/DC50%1/2
exists $data->{"rootlogger"} and not exists $data->{"rootLogger"}
exists $data->{"rootlogger"}
not exists $data->{"rootLogger"}
Truth table66%2/3
A and not(B)
A= exists $data->{"rootlogger"}B= not exists $data->{"rootLogger"}
| |||||||||||||||||||||||||||||||||||||||||||
| 160 | ! exists $data->{rootLogger}) { | ||||||||||||||||||||||||||||||||||||||||||
| 161 | 1 | $data->{rootLogger} = $data->{rootlogger}; | |||||||||||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||
| 164 | # Find all logger definitions in the conf file. Start | ||||||||||||||||||||||||||||||||||||||||||
| 165 | # with root loggers. | ||||||||||||||||||||||||||||||||||||||||||
| 166 | 154 | ▶ | if(exists $data->{rootLogger}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 167 | 23 | $LOGGERS_DEFINED++; | |||||||||||||||||||||||||||||||||||||||||
| 168 | 23 | push @loggers, ["", $data->{rootLogger}->{value}]; | |||||||||||||||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||
| 171 | # Check if we've got a system-wide threshold setting | ||||||||||||||||||||||||||||||||||||||||||
| 172 | 154 | ▶ | if(exists $data->{threshold}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 173 | # yes, we do. | ||||||||||||||||||||||||||||||||||||||||||
| 174 | 4 | $system_wide_threshold = $data->{threshold}->{value}; | |||||||||||||||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||
| 177 | 154 | ▶ | if (exists $data->{oneMessagePerAppender}){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 178 | $Log::Log4perl::one_message_per_appender = | ||||||||||||||||||||||||||||||||||||||||||
| 179 | 1 | $data->{oneMessagePerAppender}->{value}; | |||||||||||||||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||
| 182 | 154 | ▶ | if(exists $data->{utcDateTimes}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 183 | 2 | require Log::Log4perl::DateFormat; | |||||||||||||||||||||||||||||||||||||||||
| 184 | # Need to split this up in two lines, or CVS will | ||||||||||||||||||||||||||||||||||||||||||
| 185 | # mess it up. | ||||||||||||||||||||||||||||||||||||||||||
| 186 | $Log::Log4perl::DateFormat::GMTIME = | ||||||||||||||||||||||||||||||||||||||||||
| 187 | 2 | !!$data->{utcDateTimes}->{value}; | |||||||||||||||||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||
| 190 | # Boolean filters | ||||||||||||||||||||||||||||||||||||||||||
| 191 | 154 | my %boolean_filters = (); | |||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||
| 193 | # Continue with lower level loggers. Both 'logger' and 'category' | ||||||||||||||||||||||||||||||||||||||||||
| 194 | # are valid keywords. Also 'additivity' is one, having a logger | ||||||||||||||||||||||||||||||||||||||||||
| 195 | # attached. We'll differentiate between the two further down. | ||||||||||||||||||||||||||||||||||||||||||
| 196 | 154 | for my $key (qw(logger category additivity PatternLayout filter)) { | |||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||||
| 198 | 769 | ▶ | if(exists $data->{$key}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||
| 200 | 144 | for my $path (@{leaf_paths($data->{$key})}) { | |||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||
| 202 | 200 | print "Path before: @$path\n" if _INTERNAL_DEBUG; | |||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||
| 204 | 200 | my $value = boolean_to_perlish(pop @$path); | |||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||
| 206 | 200 | pop @$path; # Drop the 'value' keyword part | |||||||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||||||||
| 208 | 200 | ▶ | if($key eq "additivity") { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 209 | # This isn't a logger but an additivity setting. | ||||||||||||||||||||||||||||||||||||||||||
| 210 | # Save it in a hash under the logger's name for later. | ||||||||||||||||||||||||||||||||||||||||||
| 211 | 4 | $additivity{join('.', @$path)} = $value; | |||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||
| 213 | #a global user-defined conversion specifier (cspec) | ||||||||||||||||||||||||||||||||||||||||||
| 214 | }elsif ($key eq "PatternLayout"){ | ||||||||||||||||||||||||||||||||||||||||||
| 215 | 3 | &add_global_cspec(@$path[-1], $value); | |||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||
| 217 | }elsif ($key eq "filter"){ | ||||||||||||||||||||||||||||||||||||||||||
| 218 | 52 | print "Found entry @$path\n" if _INTERNAL_DEBUG; | |||||||||||||||||||||||||||||||||||||||||
| 219 | 52 | $filter_names{@$path[0]}++; | |||||||||||||||||||||||||||||||||||||||||
| 220 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||||||||||
| 222 | 141 | ▶ | if (ref($value) eq "ARRAY") { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 223 | 0 | die "Multiple definitions of logger ".join('.',@$path)." in log4perl config"; | |||||||||||||||||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||
| 226 | # This is a regular logger | ||||||||||||||||||||||||||||||||||||||||||
| 227 | 141 | $LOGGERS_DEFINED++; | |||||||||||||||||||||||||||||||||||||||||
| 228 | 141 | push @loggers, [join('.', @$path), $value]; | |||||||||||||||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||
| 234 | # Now go over all filters found by name | ||||||||||||||||||||||||||||||||||||||||||
| 235 | 153 | for my $filter_name (sort keys %filter_names) { | |||||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||||||
| 237 | 22 | print "Checking filter $filter_name\n" if _INTERNAL_DEBUG; | |||||||||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||||||||||
| 239 | # The boolean filter needs all other filters already | ||||||||||||||||||||||||||||||||||||||||||
| 240 | # initialized, defer its initialization | ||||||||||||||||||||||||||||||||||||||||||
| 241 | 22 | ▶ | if($data->{filter}->{$filter_name}->{value} eq | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 242 | "Log::Log4perl::Filter::Boolean") { | ||||||||||||||||||||||||||||||||||||||||||
| 243 | 3 | print "Boolean filter ($filter_name)\n" if _INTERNAL_DEBUG; | |||||||||||||||||||||||||||||||||||||||||
| 244 | 3 | $boolean_filters{$filter_name}++; | |||||||||||||||||||||||||||||||||||||||||
| 245 | 3 | next; | |||||||||||||||||||||||||||||||||||||||||
| 246 | } | ||||||||||||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||||||||||||
| 248 | 19 | my $type = $data->{filter}->{$filter_name}->{value}; | |||||||||||||||||||||||||||||||||||||||||
| 249 | 19 | ▶ | if(my $code = compile_if_perl($type)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 250 | 4 | $type = $code; | |||||||||||||||||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||||||||
| 253 | 18 | print "Filter $filter_name is of type $type\n" if _INTERNAL_DEBUG; | |||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||
| 255 | 18 | my $filter; | |||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||||
| 257 | 18 | ▶ | if(ref($type) eq "CODE") { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 258 | # Subroutine - map into generic Log::Log4perl::Filter class | ||||||||||||||||||||||||||||||||||||||||||
| 259 | 4 | $filter = Log::Log4perl::Filter->new($filter_name, $type); | |||||||||||||||||||||||||||||||||||||||||
| 260 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 261 | # Filter class | ||||||||||||||||||||||||||||||||||||||||||
| 262 | 14 | ▶ | die "Filter class '$type' doesn't exist" unless | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 263 | Log::Log4perl::Util::module_available($type); | ||||||||||||||||||||||||||||||||||||||||||
| 264 | 13 | ▶ | eval "require $type" or die "Require of $type failed ($!)"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||||||||
| 266 | # Invoke with all defined parameter | ||||||||||||||||||||||||||||||||||||||||||
| 267 | # key/values (except the key 'value' which is the entry | ||||||||||||||||||||||||||||||||||||||||||
| 268 | # for the class) | ||||||||||||||||||||||||||||||||||||||||||
| 269 | $filter = $type->new(name => $filter_name, | ||||||||||||||||||||||||||||||||||||||||||
| 270 | 27 | map { $_ => $data->{filter}->{$filter_name}->{$_}->{value} } | |||||||||||||||||||||||||||||||||||||||||
| 271 | 40 | grep { $_ ne "value" } | |||||||||||||||||||||||||||||||||||||||||
| 272 | 13 | sort keys %{$data->{filter}->{$filter_name}}); | |||||||||||||||||||||||||||||||||||||||||
| 273 | } | ||||||||||||||||||||||||||||||||||||||||||
| 274 | # Register filter with the global filter registry | ||||||||||||||||||||||||||||||||||||||||||
| 275 | 16 | $filter->register(); | |||||||||||||||||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||||||||||||
| 278 | # Initialize boolean filters (they need the other filters to be | ||||||||||||||||||||||||||||||||||||||||||
| 279 | # initialized to be able to compile their logic) | ||||||||||||||||||||||||||||||||||||||||||
| 280 | 150 | for my $name (sort keys %boolean_filters) { | |||||||||||||||||||||||||||||||||||||||||
| 281 | 3 | my $logic = $data->{filter}->{$name}->{logic}->{value}; | |||||||||||||||||||||||||||||||||||||||||
| 282 | 3 | ▶ | die "No logic defined for boolean filter $name" unless defined $logic; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 283 | 3 | my $filter = Log::Log4perl::Filter::Boolean->new( | |||||||||||||||||||||||||||||||||||||||||
| 284 | name => $name, | ||||||||||||||||||||||||||||||||||||||||||
| 285 | logic => $logic); | ||||||||||||||||||||||||||||||||||||||||||
| 286 | 3 | $filter->register(); | |||||||||||||||||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||||||||||||
| 289 | 150 | for (@loggers) { | |||||||||||||||||||||||||||||||||||||||||
| 290 | 160 | my($name, $value) = @$_; | |||||||||||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||||||||||||
| 292 | 160 | my $logger = Log::Log4perl::Logger->get_logger($name); | |||||||||||||||||||||||||||||||||||||||||
| 293 | 160 | my ($level, @appnames) = split /\s*,\s*/, $value; | |||||||||||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||||||||||||
| 295 | 160 | $logger->level( | |||||||||||||||||||||||||||||||||||||||||
| 296 | Log::Log4perl::Level::to_priority($level), | ||||||||||||||||||||||||||||||||||||||||||
| 297 | 'dont_reset_all'); | ||||||||||||||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||||||||||||
| 299 | 159 | ▶ | if(exists $additivity{$name}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 300 | 4 | $logger->additivity($additivity{$name}, 1); | |||||||||||||||||||||||||||||||||||||||||
| 301 | } | ||||||||||||||||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||||||||||||||
| 303 | 159 | for my $appname (@appnames) { | |||||||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||||||||
| 305 | 165 | my $appender = create_appender_instance( | |||||||||||||||||||||||||||||||||||||||||
| 306 | $data, $appname, \%appenders_created, \@post_config_subs, | ||||||||||||||||||||||||||||||||||||||||||
| 307 | $system_wide_threshold); | ||||||||||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||||||||||
| 309 | 155 | $logger->add_appender($appender, 'dont_reset_all'); | |||||||||||||||||||||||||||||||||||||||||
| 310 | 155 | set_appender_by_name($appname, $appender, \%appenders_created); | |||||||||||||||||||||||||||||||||||||||||
| 311 | } | ||||||||||||||||||||||||||||||||||||||||||
| 312 | } | ||||||||||||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||||||||||||
| 314 | #run post_config subs | ||||||||||||||||||||||||||||||||||||||||||
| 315 | 139 | for(@post_config_subs) { | |||||||||||||||||||||||||||||||||||||||||
| 316 | 9 | $_->(); | |||||||||||||||||||||||||||||||||||||||||
| 317 | } | ||||||||||||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||||||||||||
| 319 | #now we're done, set up all the output methods (e.g. ->debug('...')) | ||||||||||||||||||||||||||||||||||||||||||
| 320 | 139 | Log::Log4perl::Logger::reset_all_output_methods(); | |||||||||||||||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||||||||||||||||
| 322 | #Run a sanity test on the config not disabled | ||||||||||||||||||||||||||||||||||||||||||
| 323 | 139 | ▶ | if($Log::Log4perl::Config::CONFIG_INTEGRITY_CHECK and | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$Log::Log4perl::Config::CONFIG_INTEGRITY_CHECK and not config_is_sane()
MC/DC100%2/2
$Log::Log4perl::Config::CONFIG_INTEGRITY_CHECK and not config_is_sane()
$Log::Log4perl::Config::CONFIG_INTEGRITY_CHECK
not config_is_sane()
Truth table100%3/3
A and not(B)
A= $Log::Log4perl::Config::CONFIG_INTEGRITY_CHECKB= not config_is_sane()
| |||||||||||||||||||||||||||||||||||||||||||
| 324 | !config_is_sane()) { | ||||||||||||||||||||||||||||||||||||||||||
| 325 | 5 | warn "Log::Log4perl configuration looks suspicious: ", | |||||||||||||||||||||||||||||||||||||||||
| 326 | "$CONFIG_INTEGRITY_ERROR"; | ||||||||||||||||||||||||||||||||||||||||||
| 327 | } | ||||||||||||||||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||||||||||||||||
| 329 | # Successful init(), save config for later | ||||||||||||||||||||||||||||||||||||||||||
| 330 | 139 | $OLD_CONFIG = $data; | |||||||||||||||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||||||||||||||||
| 332 | 139 | $Log::Log4perl::Logger::INITIALIZED = 1; | |||||||||||||||||||||||||||||||||||||||||
| 333 | } | ||||||||||||||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||||||||||||
| 335 | ################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 336 | 130 | ▶ | sub config_is_sane { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
config_is_sane: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 337 | ################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 338 | 130 | ▶ | if(! $LOGGERS_DEFINED) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 339 | 4 | $CONFIG_INTEGRITY_ERROR = "No loggers defined"; | |||||||||||||||||||||||||||||||||||||||||
| 340 | 4 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 341 | } | ||||||||||||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||||||||||||
| 343 | 126 | ▶ | if(scalar keys %Log::Log4perl::Logger::APPENDER_BY_NAME == 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 344 | 1 | $CONFIG_INTEGRITY_ERROR = "No appenders defined"; | |||||||||||||||||||||||||||||||||||||||||
| 345 | 1 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 346 | } | ||||||||||||||||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||||||||||||||||
| 348 | 125 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 349 | } | ||||||||||||||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||||||||||||
| 351 | ################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 352 | 174 | ▶ | sub create_appender_instance { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
create_appender_instance: called CC=19 SCAR=29.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 353 | ################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 354 | 174 | my($data, $appname, $appenders_created, $post_config_subs, | |||||||||||||||||||||||||||||||||||||||||
| 355 | $system_wide_threshold) = @_; | ||||||||||||||||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||||||||||||||||
| 357 | 174 | my $appenderclass = get_appender_by_name( | |||||||||||||||||||||||||||||||||||||||||
| 358 | $data, $appname, $appenders_created); | ||||||||||||||||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||||||||||||||||
| 360 | 174 | print "appenderclass=$appenderclass\n" if _INTERNAL_DEBUG; | |||||||||||||||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||||||||||||||||
| 362 | 174 | my $appender; | |||||||||||||||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||||||||||||||||
| 364 | 174 | ▶ | if (ref $appenderclass) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 365 | 7 | $appender = $appenderclass; | |||||||||||||||||||||||||||||||||||||||||
| 366 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 367 | 167 | ▶ | die "ERROR: you didn't tell me how to " . | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 368 | "implement your appender '$appname'" | ||||||||||||||||||||||||||||||||||||||||||
| 369 | unless $appenderclass; | ||||||||||||||||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||||||||||||||||
| 371 | 166 | ▶ | if (Log::Log4perl::JavaMap::translate($appenderclass)){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 372 | # It's Java. Try to map | ||||||||||||||||||||||||||||||||||||||||||
| 373 | 13 | print "Trying to map Java $appname\n" if _INTERNAL_DEBUG; | |||||||||||||||||||||||||||||||||||||||||
| 374 | $appender = Log::Log4perl::JavaMap::get($appname, | ||||||||||||||||||||||||||||||||||||||||||
| 375 | 13 | $data->{appender}->{$appname}); | |||||||||||||||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||||||||||||||||
| 377 | }else{ | ||||||||||||||||||||||||||||||||||||||||||
| 378 | # It's Perl | ||||||||||||||||||||||||||||||||||||||||||
| 379 | 474 | ▶ | my @params = grep { $_ ne "layout" and | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$_ ne 'layout' && $_ ne 'value'
MC/DC100%2/2
$_ ne 'layout' && $_ ne 'value'
$_ ne 'layout'
$_ ne 'value'
Truth table100%3/3
A && B
A= $_ ne 'layout'B= $_ ne 'value'
| |||||||||||||||||||||||||||||||||||||||||||
| 380 | $_ ne "value" | ||||||||||||||||||||||||||||||||||||||||||
| 381 | 153 | } sort keys %{$data->{appender}->{$appname}}; | |||||||||||||||||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||||||||||||||||
| 383 | 153 | my %param = (); | |||||||||||||||||||||||||||||||||||||||||
| 384 | 153 | foreach my $pname (@params){ | |||||||||||||||||||||||||||||||||||||||||
| 385 | #this could be simple value like | ||||||||||||||||||||||||||||||||||||||||||
| 386 | #{appender}{myAppender}{file}{value} => 'log.txt' | ||||||||||||||||||||||||||||||||||||||||||
| 387 | #or a structure like | ||||||||||||||||||||||||||||||||||||||||||
| 388 | #{appender}{myAppender}{login} => | ||||||||||||||||||||||||||||||||||||||||||
| 389 | # { name => {value => 'bob'}, | ||||||||||||||||||||||||||||||||||||||||||
| 390 | # pwd => {value => 'xxx'}, | ||||||||||||||||||||||||||||||||||||||||||
| 391 | # } | ||||||||||||||||||||||||||||||||||||||||||
| 392 | #in the latter case we send a hashref to the appender | ||||||||||||||||||||||||||||||||||||||||||
| 393 | 179 | ▶ | if (exists $data->{appender}{$appname} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 394 | {$pname}{value} ) { | ||||||||||||||||||||||||||||||||||||||||||
| 395 | $param{$pname} = $data->{appender}{$appname} | ||||||||||||||||||||||||||||||||||||||||||
| 396 | 174 | {$pname}{value}; | |||||||||||||||||||||||||||||||||||||||||
| 397 | }else{ | ||||||||||||||||||||||||||||||||||||||||||
| 398 | $param{$pname} = {map {$_ => $data->{appender} | ||||||||||||||||||||||||||||||||||||||||||
| 399 | {$appname} | ||||||||||||||||||||||||||||||||||||||||||
| 400 | {$pname} | ||||||||||||||||||||||||||||||||||||||||||
| 401 | {$_} | ||||||||||||||||||||||||||||||||||||||||||
| 402 | 14 | {value}} | |||||||||||||||||||||||||||||||||||||||||
| 403 | 5 | sort keys %{$data->{appender} | |||||||||||||||||||||||||||||||||||||||||
| 404 | {$appname} | ||||||||||||||||||||||||||||||||||||||||||
| 405 | 5 | {$pname}} | |||||||||||||||||||||||||||||||||||||||||
| 406 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 407 | } | ||||||||||||||||||||||||||||||||||||||||||
| 408 | |||||||||||||||||||||||||||||||||||||||||||
| 409 | } | ||||||||||||||||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||||||||||||||||
| 411 | 153 | my $depends_on = []; | |||||||||||||||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||||||||||||||||
| 413 | 153 | $appender = Log::Log4perl::Appender->new( | |||||||||||||||||||||||||||||||||||||||||
| 414 | $appenderclass, | ||||||||||||||||||||||||||||||||||||||||||
| 415 | name => $appname, | ||||||||||||||||||||||||||||||||||||||||||
| 416 | l4p_post_config_subs => $post_config_subs, | ||||||||||||||||||||||||||||||||||||||||||
| 417 | l4p_depends_on => $depends_on, | ||||||||||||||||||||||||||||||||||||||||||
| 418 | %param, | ||||||||||||||||||||||||||||||||||||||||||
| 419 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||||||||||||||||
| 421 | 151 | for my $dependency (@$depends_on) { | |||||||||||||||||||||||||||||||||||||||||
| 422 | # If this appender indicates that it needs other appenders | ||||||||||||||||||||||||||||||||||||||||||
| 423 | # to exist (e.g. because it's a composite appender that | ||||||||||||||||||||||||||||||||||||||||||
| 424 | # relays messages on to its appender-refs) then we're | ||||||||||||||||||||||||||||||||||||||||||
| 425 | # creating their instances here. Reason for this is that | ||||||||||||||||||||||||||||||||||||||||||
| 426 | # these appenders are not attached to any logger and are | ||||||||||||||||||||||||||||||||||||||||||
| 427 | # therefore missed by the config parser which goes through | ||||||||||||||||||||||||||||||||||||||||||
| 428 | # the defined loggers and just creates *their* attached | ||||||||||||||||||||||||||||||||||||||||||
| 429 | # appenders. | ||||||||||||||||||||||||||||||||||||||||||
| 430 | 9 | $appender->composite(1); | |||||||||||||||||||||||||||||||||||||||||
| 431 | 9 | ▶ | next if exists $appenders_created->{$appname}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 432 | 9 | my $app = create_appender_instance($data, $dependency, | |||||||||||||||||||||||||||||||||||||||||
| 433 | $appenders_created, | ||||||||||||||||||||||||||||||||||||||||||
| 434 | $post_config_subs); | ||||||||||||||||||||||||||||||||||||||||||
| 435 | # If the appender appended a subroutine to $post_config_subs | ||||||||||||||||||||||||||||||||||||||||||
| 436 | # (a reference to an array of subroutines) | ||||||||||||||||||||||||||||||||||||||||||
| 437 | # here, the configuration parser will later execute this | ||||||||||||||||||||||||||||||||||||||||||
| 438 | # method. This is used by a composite appender which needs | ||||||||||||||||||||||||||||||||||||||||||
| 439 | # to make sure all of its appender-refs are available when | ||||||||||||||||||||||||||||||||||||||||||
| 440 | # all configuration settings are done. | ||||||||||||||||||||||||||||||||||||||||||
| 441 | |||||||||||||||||||||||||||||||||||||||||||
| 442 | # Smuggle this sub-appender into the hash of known appenders | ||||||||||||||||||||||||||||||||||||||||||
| 443 | # without attaching it to any logger directly. | ||||||||||||||||||||||||||||||||||||||||||
| 444 | $ | ||||||||||||||||||||||||||||||||||||||||||
| 445 | 9 | Log::Log4perl::Logger::APPENDER_BY_NAME{$dependency} = $app; | |||||||||||||||||||||||||||||||||||||||||
| 446 | } | ||||||||||||||||||||||||||||||||||||||||||
| 447 | } | ||||||||||||||||||||||||||||||||||||||||||
| 448 | } | ||||||||||||||||||||||||||||||||||||||||||
| 449 | |||||||||||||||||||||||||||||||||||||||||||
| 450 | 171 | ▶ | add_layout_by_name($data, $appender, $appname) unless | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 451 | $appender->composite(); | ||||||||||||||||||||||||||||||||||||||||||
| 452 | |||||||||||||||||||||||||||||||||||||||||||
| 453 | # Check for appender thresholds | ||||||||||||||||||||||||||||||||||||||||||
| 454 | my $threshold = | ||||||||||||||||||||||||||||||||||||||||||
| 455 | 165 | $data->{appender}->{$appname}->{Threshold}->{value}; | |||||||||||||||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||||||||||||||||
| 457 | 165 | ▶ | if(defined $system_wide_threshold and | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $system_wide_threshold and not defined $threshold
MC/DC100%2/2
defined $system_wide_threshold and not defined $threshold
defined $system_wide_threshold
not defined $threshold
Truth table100%3/3
A and not(B)
A= defined $system_wide_thresholdB= not defined $threshold
| |||||||||||||||||||||||||||||||||||||||||||
| 458 | !defined $threshold) { | ||||||||||||||||||||||||||||||||||||||||||
| 459 | 1 | $threshold = $system_wide_threshold; | |||||||||||||||||||||||||||||||||||||||||
| 460 | } | ||||||||||||||||||||||||||||||||||||||||||
| 461 | |||||||||||||||||||||||||||||||||||||||||||
| 462 | 165 | ▶ | if(defined $threshold) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 463 | # Need to split into two lines because of CVS | ||||||||||||||||||||||||||||||||||||||||||
| 464 | $appender->threshold($ | ||||||||||||||||||||||||||||||||||||||||||
| 465 | 13 | Log::Log4perl::Level::PRIORITY{$threshold}); | |||||||||||||||||||||||||||||||||||||||||
| 466 | } | ||||||||||||||||||||||||||||||||||||||||||
| 467 | |||||||||||||||||||||||||||||||||||||||||||
| 468 | # Check for custom filters attached to the appender | ||||||||||||||||||||||||||||||||||||||||||
| 469 | my $filtername = | ||||||||||||||||||||||||||||||||||||||||||
| 470 | 165 | $data->{appender}->{$appname}->{Filter}->{value}; | |||||||||||||||||||||||||||||||||||||||||
| 471 | 165 | ▶ | if(defined $filtername) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 472 | # Need to split into two lines because of CVS | ||||||||||||||||||||||||||||||||||||||||||
| 473 | 12 | my $filter = Log::Log4perl::Filter::by_name($filtername); | |||||||||||||||||||||||||||||||||||||||||
| 474 | 12 | ▶ | die "Filter $filtername doesn't exist" unless defined $filter; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 475 | 12 | $appender->filter($filter); | |||||||||||||||||||||||||||||||||||||||||
| 476 | } | ||||||||||||||||||||||||||||||||||||||||||
| 477 | |||||||||||||||||||||||||||||||||||||||||||
| 478 | 165 | ▶ | if(defined $system_wide_threshold and | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
defined $system_wide_threshold and defined $threshold and $Log::Log4perl::Level::PRIORITY{$system_wide_threshold} > $Log::Log4perl::Level::PRIORITY{$threshold}
defined $system_wide_threshold and defined $threshold
MC/DC66%2/3
defined $system_wide_threshold and defined $threshold and $Log::Log4perl::Level::PRIORITY{$system_wide_threshold} > $Log::Log4perl::Level::PRIORITY{$threshold}
defined $system_wide_threshold
defined $threshold
$Log::Log4perl::Level::PRIORITY{$system_wide_threshold} > $Log::Log4perl::Level::PRIORITY{$threshold}
Truth table75%3/4
A and B and C
A= defined $system_wide_thresholdB= defined $thresholdC= $Log::Log4perl::Level::PRIORITY{$system_wide_threshold} > $Log::Log4perl::Level::PRIORITY{$threshold}
| |||||||||||||||||||||||||||||||||||||||||||
| 479 | defined $threshold and | ||||||||||||||||||||||||||||||||||||||||||
| 480 | $ | ||||||||||||||||||||||||||||||||||||||||||
| 481 | Log::Log4perl::Level::PRIORITY{$system_wide_threshold} > | ||||||||||||||||||||||||||||||||||||||||||
| 482 | $ | ||||||||||||||||||||||||||||||||||||||||||
| 483 | Log::Log4perl::Level::PRIORITY{$threshold} | ||||||||||||||||||||||||||||||||||||||||||
| 484 | ) { | ||||||||||||||||||||||||||||||||||||||||||
| 485 | $appender->threshold($ | ||||||||||||||||||||||||||||||||||||||||||
| 486 | 3 | Log::Log4perl::Level::PRIORITY{$system_wide_threshold}); | |||||||||||||||||||||||||||||||||||||||||
| 487 | } | ||||||||||||||||||||||||||||||||||||||||||
| 488 | |||||||||||||||||||||||||||||||||||||||||||
| 489 | 165 | ▶ | if(exists $data->{appender}->{$appname}->{threshold}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 490 | 1 | die "invalid keyword 'threshold' - perhaps you meant 'Threshold'?"; | |||||||||||||||||||||||||||||||||||||||||
| 491 | } | ||||||||||||||||||||||||||||||||||||||||||
| 492 | |||||||||||||||||||||||||||||||||||||||||||
| 493 | 164 | return $appender; | |||||||||||||||||||||||||||||||||||||||||
| 494 | } | ||||||||||||||||||||||||||||||||||||||||||
| 495 | |||||||||||||||||||||||||||||||||||||||||||
| 496 | ########################################### | ||||||||||||||||||||||||||||||||||||||||||
| 497 | 162 | ▶ | sub add_layout_by_name { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_layout_by_name: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 498 | ########################################### | ||||||||||||||||||||||||||||||||||||||||||
| 499 | 162 | my($data, $appender, $appender_name) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 500 | |||||||||||||||||||||||||||||||||||||||||||
| 501 | 162 | my $layout_class = $data->{appender}->{$appender_name}->{layout}->{value}; | |||||||||||||||||||||||||||||||||||||||||
| 502 | |||||||||||||||||||||||||||||||||||||||||||
| 503 | 162 | ▶ | die "Layout not specified for appender $appender_name" unless $layout_class; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 504 | |||||||||||||||||||||||||||||||||||||||||||
| 505 | 160 | $layout_class =~ s/org.apache.log4j./Log::Log4perl::Layout::/; | |||||||||||||||||||||||||||||||||||||||||
| 506 | |||||||||||||||||||||||||||||||||||||||||||
| 507 | # Check if we have this layout class | ||||||||||||||||||||||||||||||||||||||||||
| 508 | 160 | ▶ | if(!Log::Log4perl::Util::module_available($layout_class)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 509 | 30 | ▶ | if(Log::Log4perl::Util::module_available( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 510 | "Log::Log4perl::Layout::$layout_class")) { | ||||||||||||||||||||||||||||||||||||||||||
| 511 | # Someone used the layout shortcut, use the fully qualified | ||||||||||||||||||||||||||||||||||||||||||
| 512 | # module name instead. | ||||||||||||||||||||||||||||||||||||||||||
| 513 | 28 | $layout_class = "Log::Log4perl::Layout::$layout_class"; | |||||||||||||||||||||||||||||||||||||||||
| 514 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 515 | 2 | die "ERROR: trying to set layout for $appender_name to " . | |||||||||||||||||||||||||||||||||||||||||
| 516 | "'$layout_class' failed ($@)"; | ||||||||||||||||||||||||||||||||||||||||||
| 517 | } | ||||||||||||||||||||||||||||||||||||||||||
| 518 | } | ||||||||||||||||||||||||||||||||||||||||||
| 519 | 158 | ▶ | Log::Log4perl::Util::module_available($layout_class) or | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 520 | die "Require to $layout_class failed ($@)"; | ||||||||||||||||||||||||||||||||||||||||||
| 521 | |||||||||||||||||||||||||||||||||||||||||||
| 522 | $appender->layout($layout_class->new( | ||||||||||||||||||||||||||||||||||||||||||
| 523 | $data->{appender}->{$appender_name}->{layout}, | ||||||||||||||||||||||||||||||||||||||||||
| 524 | 158 | )); | |||||||||||||||||||||||||||||||||||||||||
| 525 | } | ||||||||||||||||||||||||||||||||||||||||||
| 526 | |||||||||||||||||||||||||||||||||||||||||||
| 527 | ########################################### | ||||||||||||||||||||||||||||||||||||||||||
| 528 | 174 | ▶ | sub get_appender_by_name { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_appender_by_name: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 529 | ########################################### | ||||||||||||||||||||||||||||||||||||||||||
| 530 | 174 | my($data, $name, $appenders_created) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 531 | |||||||||||||||||||||||||||||||||||||||||||
| 532 | 174 | ▶ | if (exists $appenders_created->{$name}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 533 | 7 | return $appenders_created->{$name}; | |||||||||||||||||||||||||||||||||||||||||
| 534 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 535 | 167 | return $data->{appender}->{$name}->{value}; | |||||||||||||||||||||||||||||||||||||||||
| 536 | } | ||||||||||||||||||||||||||||||||||||||||||
| 537 | } | ||||||||||||||||||||||||||||||||||||||||||
| 538 | |||||||||||||||||||||||||||||||||||||||||||
| 539 | ########################################### | ||||||||||||||||||||||||||||||||||||||||||
| 540 | 155 | ▶ | sub set_appender_by_name { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_appender_by_name: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 541 | ########################################### | ||||||||||||||||||||||||||||||||||||||||||
| 542 | # keep track of appenders we've already created | ||||||||||||||||||||||||||||||||||||||||||
| 543 | ########################################### | ||||||||||||||||||||||||||||||||||||||||||
| 544 | 155 | my($appname, $appender, $appenders_created) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 545 | |||||||||||||||||||||||||||||||||||||||||||
| 546 | 155 | ▶ | $appenders_created->{$appname} ||= $appender; | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$appenders_created->{$appname} ||= $appender
MC/DC0%0/2
$appenders_created->{$appname} ||= $appender
$appenders_created->{$appname}
$appender
Truth table66%2/3
A ||= B
A= $appenders_created->{$appname}B= $appender
| |||||||||||||||||||||||||||||||||||||||||||
| 547 | } | ||||||||||||||||||||||||||||||||||||||||||
| 548 | |||||||||||||||||||||||||||||||||||||||||||
| 549 | ################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 550 | 3 | ▶ | sub add_global_cspec { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_global_cspec: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 551 | ################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 552 | # the config file said | ||||||||||||||||||||||||||||||||||||||||||
| 553 | # log4j.PatternLayout.cspec.Z=sub {return $$*2} | ||||||||||||||||||||||||||||||||||||||||||
| 554 | ################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 555 | 3 | my ($letter, $perlcode) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 556 | |||||||||||||||||||||||||||||||||||||||||||
| 557 | 3 | ▶ | die "error: only single letters allowed in log4j.PatternLayout.cspec.$letter" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 558 | unless ($letter =~ /^[a-zA-Z]$/); | ||||||||||||||||||||||||||||||||||||||||||
| 559 | |||||||||||||||||||||||||||||||||||||||||||
| 560 | 3 | Log::Log4perl::Layout::PatternLayout::add_global_cspec($letter, $perlcode); | |||||||||||||||||||||||||||||||||||||||||
| 561 | } | ||||||||||||||||||||||||||||||||||||||||||
| 562 | |||||||||||||||||||||||||||||||||||||||||||
| 563 | 54 | my $LWP_USER_AGENT; | |||||||||||||||||||||||||||||||||||||||||
| 564 | sub set_LWP_UserAgent | ||||||||||||||||||||||||||||||||||||||||||
| 565 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_LWP_UserAgent: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 566 | 0 | $LWP_USER_AGENT = shift; | |||||||||||||||||||||||||||||||||||||||||
| 567 | } | ||||||||||||||||||||||||||||||||||||||||||
| 568 | |||||||||||||||||||||||||||||||||||||||||||
| 569 | |||||||||||||||||||||||||||||||||||||||||||
| 570 | ########################################### | ||||||||||||||||||||||||||||||||||||||||||
| 571 | 163 | ▶ | sub config_read { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
config_read: called CC=18 SCAR=37.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 572 | ########################################### | ||||||||||||||||||||||||||||||||||||||||||
| 573 | # Read the lib4j configuration and store the | ||||||||||||||||||||||||||||||||||||||||||
| 574 | # values into a nested hash structure. | ||||||||||||||||||||||||||||||||||||||||||
| 575 | ########################################### | ||||||||||||||||||||||||||||||||||||||||||
| 576 | 163 | my($config) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 577 | |||||||||||||||||||||||||||||||||||||||||||
| 578 | 163 | ▶ | die "Configuration not defined" unless defined $config; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 579 | |||||||||||||||||||||||||||||||||||||||||||
| 580 | 163 | my @text; | |||||||||||||||||||||||||||||||||||||||||
| 581 | my $parser; | ||||||||||||||||||||||||||||||||||||||||||
| 582 | |||||||||||||||||||||||||||||||||||||||||||
| 583 | 163 | $CONFIG_FILE_READS++; # Count for statistical purposes | |||||||||||||||||||||||||||||||||||||||||
| 584 | |||||||||||||||||||||||||||||||||||||||||||
| 585 | 163 | my $base_configurator = Log::Log4perl::Config::BaseConfigurator->new( | |||||||||||||||||||||||||||||||||||||||||
| 586 | utf8 => $UTF8, | ||||||||||||||||||||||||||||||||||||||||||
| 587 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 588 | |||||||||||||||||||||||||||||||||||||||||||
| 589 | 163 | my $data = {}; | |||||||||||||||||||||||||||||||||||||||||
| 590 | |||||||||||||||||||||||||||||||||||||||||||
| 591 | 163 | ▶ | if (ref($config) eq 'HASH') { # convert the hashref into a list | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 592 | # of name/value pairs | ||||||||||||||||||||||||||||||||||||||||||
| 593 | 2 | print "Reading config from hash\n" if _INTERNAL_DEBUG; | |||||||||||||||||||||||||||||||||||||||||
| 594 | 2 | @text = (); | |||||||||||||||||||||||||||||||||||||||||
| 595 | 2 | for my $key ( sort keys %$config ) { | |||||||||||||||||||||||||||||||||||||||||
| 596 | 8 | ▶ | if( ref( $config->{$key} ) eq "CODE" ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 597 | 1 | $config->{$key} = $config->{$key}->(); | |||||||||||||||||||||||||||||||||||||||||
| 598 | } | ||||||||||||||||||||||||||||||||||||||||||
| 599 | 8 | push @text, $key . '=' . $config->{$key} . "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 600 | } | ||||||||||||||||||||||||||||||||||||||||||
| 601 | } elsif (ref $config eq 'SCALAR') { | ||||||||||||||||||||||||||||||||||||||||||
| 602 | 142 | print "Reading config from scalar\n" if _INTERNAL_DEBUG; | |||||||||||||||||||||||||||||||||||||||||
| 603 | 142 | @text = split(/\n/,$$config); | |||||||||||||||||||||||||||||||||||||||||
| 604 | |||||||||||||||||||||||||||||||||||||||||||
| 605 | ▶ | } elsif (ref $config eq 'GLOB' or | |||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
ref $config eq "GLOB" or ref $config eq "IO::File"
MC/DC50%1/2
ref $config eq "GLOB" or ref $config eq "IO::File"
ref $config eq "GLOB"
ref $config eq "IO::File"
Truth table66%2/3
A or B
A= ref $config eq "GLOB"B= ref $config eq "IO::File"
| |||||||||||||||||||||||||||||||||||||||||||
| 606 | ref $config eq 'IO::File') { | ||||||||||||||||||||||||||||||||||||||||||
| 607 | # If we have a file handle, just call the reader | ||||||||||||||||||||||||||||||||||||||||||
| 608 | 1 | print "Reading config from file handle\n" if _INTERNAL_DEBUG; | |||||||||||||||||||||||||||||||||||||||||
| 609 | 1 | @text = @{ $base_configurator->file_h_read( $config ) }; | |||||||||||||||||||||||||||||||||||||||||
| 610 | |||||||||||||||||||||||||||||||||||||||||||
| 611 | } elsif (ref $config) { | ||||||||||||||||||||||||||||||||||||||||||
| 612 | # Caller provided a config parser object, which already | ||||||||||||||||||||||||||||||||||||||||||
| 613 | # knows which file (or DB or whatever) to parse. | ||||||||||||||||||||||||||||||||||||||||||
| 614 | 1 | print "Reading config from parser object\n" if _INTERNAL_DEBUG; | |||||||||||||||||||||||||||||||||||||||||
| 615 | 1 | $data = $config->parse(); | |||||||||||||||||||||||||||||||||||||||||
| 616 | 1 | return $data; | |||||||||||||||||||||||||||||||||||||||||
| 617 | |||||||||||||||||||||||||||||||||||||||||||
| 618 | } elsif ($config =~ m|^ldap://|){ | ||||||||||||||||||||||||||||||||||||||||||
| 619 | 0 | ▶ | if(! Log::Log4perl::Util::module_available("Net::LDAP")) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 620 | 0 | die "Log4perl: missing Net::LDAP needed to parse LDAP urls\n$@\n"; | |||||||||||||||||||||||||||||||||||||||||
| 621 | } | ||||||||||||||||||||||||||||||||||||||||||
| 622 | |||||||||||||||||||||||||||||||||||||||||||
| 623 | 0 | require Net::LDAP; | |||||||||||||||||||||||||||||||||||||||||
| 624 | 0 | require Log::Log4perl::Config::LDAPConfigurator; | |||||||||||||||||||||||||||||||||||||||||
| 625 | |||||||||||||||||||||||||||||||||||||||||||
| 626 | 0 | return Log::Log4perl::Config::LDAPConfigurator->new->parse($config); | |||||||||||||||||||||||||||||||||||||||||
| 627 | |||||||||||||||||||||||||||||||||||||||||||
| 628 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 629 | |||||||||||||||||||||||||||||||||||||||||||
| 630 | 17 | ▶ | if ($config =~ /^(https?|ftp|wais|gopher|file):/){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 631 | 0 | my ($result, $ua); | |||||||||||||||||||||||||||||||||||||||||
| 632 | |||||||||||||||||||||||||||||||||||||||||||
| 633 | 0 | ▶ | die "LWP::UserAgent not available" unless | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 634 | Log::Log4perl::Util::module_available("LWP::UserAgent"); | ||||||||||||||||||||||||||||||||||||||||||
| 635 | |||||||||||||||||||||||||||||||||||||||||||
| 636 | 0 | require LWP::UserAgent; | |||||||||||||||||||||||||||||||||||||||||
| 637 | 0 | ▶ | unless (defined $LWP_USER_AGENT) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 638 | 0 | $LWP_USER_AGENT = LWP::UserAgent->new; | |||||||||||||||||||||||||||||||||||||||||
| 639 | |||||||||||||||||||||||||||||||||||||||||||
| 640 | # Load proxy settings from environment variables, i.e.: | ||||||||||||||||||||||||||||||||||||||||||
| 641 | # http_proxy, ftp_proxy, no_proxy etc (see LWP::UserAgent) | ||||||||||||||||||||||||||||||||||||||||||
| 642 | # You need these to go thru firewalls. | ||||||||||||||||||||||||||||||||||||||||||
| 643 | 0 | $LWP_USER_AGENT->env_proxy; | |||||||||||||||||||||||||||||||||||||||||
| 644 | } | ||||||||||||||||||||||||||||||||||||||||||
| 645 | 0 | $ua = $LWP_USER_AGENT; | |||||||||||||||||||||||||||||||||||||||||
| 646 | |||||||||||||||||||||||||||||||||||||||||||
| 647 | 0 | my $req = new HTTP::Request GET => $config; | |||||||||||||||||||||||||||||||||||||||||
| 648 | 0 | my $res = $ua->request($req); | |||||||||||||||||||||||||||||||||||||||||
| 649 | |||||||||||||||||||||||||||||||||||||||||||
| 650 | 0 | ▶ | if ($res->is_success) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 651 | 0 | @text = split(/\n/, $res->content); | |||||||||||||||||||||||||||||||||||||||||
| 652 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 653 | 0 | die "Log4perl couln't get $config, ". | |||||||||||||||||||||||||||||||||||||||||
| 654 | $res->message." "; | ||||||||||||||||||||||||||||||||||||||||||
| 655 | } | ||||||||||||||||||||||||||||||||||||||||||
| 656 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 657 | 17 | print "Reading config from file '$config'\n" if _INTERNAL_DEBUG; | |||||||||||||||||||||||||||||||||||||||||
| 658 | 17 | print "Reading ", -s $config, " bytes.\n" if _INTERNAL_DEBUG; | |||||||||||||||||||||||||||||||||||||||||
| 659 | # Use the BaseConfigurator's file reader to avoid duplicating | ||||||||||||||||||||||||||||||||||||||||||
| 660 | # utf8 handling here. | ||||||||||||||||||||||||||||||||||||||||||
| 661 | 17 | $base_configurator->file( $config ); | |||||||||||||||||||||||||||||||||||||||||
| 662 | 15 | @text = @{ $base_configurator->text() }; | |||||||||||||||||||||||||||||||||||||||||
| 663 | } | ||||||||||||||||||||||||||||||||||||||||||
| 664 | } | ||||||||||||||||||||||||||||||||||||||||||
| 665 | |||||||||||||||||||||||||||||||||||||||||||
| 666 | 160 | print "Reading $config: [@text]\n" if _INTERNAL_DEBUG; | |||||||||||||||||||||||||||||||||||||||||
| 667 | |||||||||||||||||||||||||||||||||||||||||||
| 668 | 160 | ▶ | if(! grep /\S/, @text) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 669 | 9 | return $data; | |||||||||||||||||||||||||||||||||||||||||
| 670 | } | ||||||||||||||||||||||||||||||||||||||||||
| 671 | |||||||||||||||||||||||||||||||||||||||||||
| 672 | 151 | ▶ | if ($text[0] =~ /^<\?xml /) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 673 | |||||||||||||||||||||||||||||||||||||||||||
| 674 | 0 | ▶ | die "XML::DOM not available" unless | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 675 | Log::Log4perl::Util::module_available("XML::DOM"); | ||||||||||||||||||||||||||||||||||||||||||
| 676 | |||||||||||||||||||||||||||||||||||||||||||
| 677 | 0 | require XML::DOM; | |||||||||||||||||||||||||||||||||||||||||
| 678 | 0 | require Log::Log4perl::Config::DOMConfigurator; | |||||||||||||||||||||||||||||||||||||||||
| 679 | |||||||||||||||||||||||||||||||||||||||||||
| 680 | 0 | XML::DOM->VERSION($Log::Log4perl::DOM_VERSION_REQUIRED); | |||||||||||||||||||||||||||||||||||||||||
| 681 | 0 | $parser = Log::Log4perl::Config::DOMConfigurator->new(); | |||||||||||||||||||||||||||||||||||||||||
| 682 | 0 | $data = $parser->parse(\@text); | |||||||||||||||||||||||||||||||||||||||||
| 683 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 684 | 151 | $parser = Log::Log4perl::Config::PropertyConfigurator->new(); | |||||||||||||||||||||||||||||||||||||||||
| 685 | 151 | $data = $parser->parse(\@text); | |||||||||||||||||||||||||||||||||||||||||
| 686 | } | ||||||||||||||||||||||||||||||||||||||||||
| 687 | |||||||||||||||||||||||||||||||||||||||||||
| 688 | 148 | $data = $parser->parse_post_process( $data, leaf_paths($data) ); | |||||||||||||||||||||||||||||||||||||||||
| 689 | |||||||||||||||||||||||||||||||||||||||||||
| 690 | 144 | return $data; | |||||||||||||||||||||||||||||||||||||||||
| 691 | } | ||||||||||||||||||||||||||||||||||||||||||
| 692 | |||||||||||||||||||||||||||||||||||||||||||
| 693 | ########################################### | ||||||||||||||||||||||||||||||||||||||||||
| 694 | 904 | ▶ | sub unlog4j { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
unlog4j: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 695 | ########################################### | ||||||||||||||||||||||||||||||||||||||||||
| 696 | 904 | my ($string) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 697 | |||||||||||||||||||||||||||||||||||||||||||
| 698 | 904 | $string =~ s#^org\.apache\.##; | |||||||||||||||||||||||||||||||||||||||||
| 699 | 904 | $string =~ s#^log4j\.##; | |||||||||||||||||||||||||||||||||||||||||
| 700 | 904 | $string =~ s#^l4p\.##; | |||||||||||||||||||||||||||||||||||||||||
| 701 | 904 | $string =~ s#^log4perl\.##i; | |||||||||||||||||||||||||||||||||||||||||
| 702 | |||||||||||||||||||||||||||||||||||||||||||
| 703 | 904 | $string =~ s#\.#::#g; | |||||||||||||||||||||||||||||||||||||||||
| 704 | |||||||||||||||||||||||||||||||||||||||||||
| 705 | 904 | return $string; | |||||||||||||||||||||||||||||||||||||||||
| 706 | } | ||||||||||||||||||||||||||||||||||||||||||
| 707 | |||||||||||||||||||||||||||||||||||||||||||
| 708 | ############################################################ | ||||||||||||||||||||||||||||||||||||||||||
| 709 | 440 | ▶ | sub leaf_paths { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
leaf_paths: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 710 | ############################################################ | ||||||||||||||||||||||||||||||||||||||||||
| 711 | # Takes a reference to a hash of hashes structure of | ||||||||||||||||||||||||||||||||||||||||||
| 712 | # arbitrary depth, walks the tree and returns a reference | ||||||||||||||||||||||||||||||||||||||||||
| 713 | # to an array of all possible leaf paths (each path is an | ||||||||||||||||||||||||||||||||||||||||||
| 714 | # array again). | ||||||||||||||||||||||||||||||||||||||||||
| 715 | # Example: { a => { b => { c => d }, e => f } } would generate | ||||||||||||||||||||||||||||||||||||||||||
| 716 | # [ [a, b, c, d], [a, e, f] ] | ||||||||||||||||||||||||||||||||||||||||||
| 717 | ############################################################ | ||||||||||||||||||||||||||||||||||||||||||
| 718 | 440 | my ($root) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 719 | |||||||||||||||||||||||||||||||||||||||||||
| 720 | 440 | my @stack = (); | |||||||||||||||||||||||||||||||||||||||||
| 721 | 440 | my @result = (); | |||||||||||||||||||||||||||||||||||||||||
| 722 | |||||||||||||||||||||||||||||||||||||||||||
| 723 | 440 | push @stack, [$root, []]; | |||||||||||||||||||||||||||||||||||||||||
| 724 | |||||||||||||||||||||||||||||||||||||||||||
| 725 | 440 | ▶ | while(@stack) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 726 | 4900 | my $item = pop @stack; | |||||||||||||||||||||||||||||||||||||||||
| 727 | |||||||||||||||||||||||||||||||||||||||||||
| 728 | 4900 | my($node, $path) = @$item; | |||||||||||||||||||||||||||||||||||||||||
| 729 | |||||||||||||||||||||||||||||||||||||||||||
| 730 | 4900 | ▶ | if(ref($node) eq "HASH") { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 731 | 2936 | for(sort keys %$node) { | |||||||||||||||||||||||||||||||||||||||||
| 732 | 4460 | push @stack, [$node->{$_}, [@$path, $_]]; | |||||||||||||||||||||||||||||||||||||||||
| 733 | } | ||||||||||||||||||||||||||||||||||||||||||
| 734 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 735 | 1964 | push @result, [@$path, $node]; | |||||||||||||||||||||||||||||||||||||||||
| 736 | } | ||||||||||||||||||||||||||||||||||||||||||
| 737 | } | ||||||||||||||||||||||||||||||||||||||||||
| 738 | 440 | return \@result; | |||||||||||||||||||||||||||||||||||||||||
| 739 | } | ||||||||||||||||||||||||||||||||||||||||||
| 740 | |||||||||||||||||||||||||||||||||||||||||||
| 741 | ########################################### | ||||||||||||||||||||||||||||||||||||||||||
| 742 | 808 | ▶ | sub leaf_path_to_hash { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
leaf_path_to_hash: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 743 | ########################################### | ||||||||||||||||||||||||||||||||||||||||||
| 744 | 808 | my($leaf_path, $data) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 745 | |||||||||||||||||||||||||||||||||||||||||||
| 746 | 808 | my $ref = \$data; | |||||||||||||||||||||||||||||||||||||||||
| 747 | |||||||||||||||||||||||||||||||||||||||||||
| 748 | 808 | for my $part ( @$leaf_path[0..$#$leaf_path-1] ) { | |||||||||||||||||||||||||||||||||||||||||
| 749 | 2884 | $ref = \$$ref->{ $part }; | |||||||||||||||||||||||||||||||||||||||||
| 750 | } | ||||||||||||||||||||||||||||||||||||||||||
| 751 | |||||||||||||||||||||||||||||||||||||||||||
| 752 | 808 | return $ref; | |||||||||||||||||||||||||||||||||||||||||
| 753 | } | ||||||||||||||||||||||||||||||||||||||||||
| 754 | |||||||||||||||||||||||||||||||||||||||||||
| 755 | ########################################### | ||||||||||||||||||||||||||||||||||||||||||
| 756 | 806 | ▶ | sub eval_if_perl { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
eval_if_perl: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 757 | ########################################### | ||||||||||||||||||||||||||||||||||||||||||
| 758 | 806 | my($value) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 759 | |||||||||||||||||||||||||||||||||||||||||||
| 760 | 806 | ▶ | if(my $cref = compile_if_perl($value)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 761 | 4 | return $cref->(); | |||||||||||||||||||||||||||||||||||||||||
| 762 | } | ||||||||||||||||||||||||||||||||||||||||||
| 763 | |||||||||||||||||||||||||||||||||||||||||||
| 764 | 798 | return $value; | |||||||||||||||||||||||||||||||||||||||||
| 765 | } | ||||||||||||||||||||||||||||||||||||||||||
| 766 | |||||||||||||||||||||||||||||||||||||||||||
| 767 | ########################################### | ||||||||||||||||||||||||||||||||||||||||||
| 768 | 842 | ▶ | sub compile_if_perl { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
compile_if_perl: called CC=7 SCAR=19.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 769 | ########################################### | ||||||||||||||||||||||||||||||||||||||||||
| 770 | 842 | my($value) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 771 | |||||||||||||||||||||||||||||||||||||||||||
| 772 | 842 | ▶ | if($value =~ /^\s*sub\s*{/ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 773 | 29 | my $mask; | |||||||||||||||||||||||||||||||||||||||||
| 774 | 29 | ▶ | unless( Log::Log4perl::Config->allow_code() ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 775 | 2 | die "\$Log::Log4perl::Config->allow_code() setting " . | |||||||||||||||||||||||||||||||||||||||||
| 776 | "prohibits Perl code in config file"; | ||||||||||||||||||||||||||||||||||||||||||
| 777 | } | ||||||||||||||||||||||||||||||||||||||||||
| 778 | 27 | ▶ | if( defined( $mask = Log::Log4perl::Config->allowed_code_ops() ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 779 | 1 | return compile_in_safe_cpt($value, $mask ); | |||||||||||||||||||||||||||||||||||||||||
| 780 | } | ||||||||||||||||||||||||||||||||||||||||||
| 781 | elsif( $mask = Log::Log4perl::Config->allowed_code_ops_convenience_map( | ||||||||||||||||||||||||||||||||||||||||||
| 782 | Log::Log4perl::Config->allow_code() | ||||||||||||||||||||||||||||||||||||||||||
| 783 | ) ) { | ||||||||||||||||||||||||||||||||||||||||||
| 784 | 6 | return compile_in_safe_cpt($value, $mask ); | |||||||||||||||||||||||||||||||||||||||||
| 785 | } | ||||||||||||||||||||||||||||||||||||||||||
| 786 | elsif( Log::Log4perl::Config->allow_code() == 1 ) { | ||||||||||||||||||||||||||||||||||||||||||
| 787 | |||||||||||||||||||||||||||||||||||||||||||
| 788 | # eval without restriction | ||||||||||||||||||||||||||||||||||||||||||
| 789 | 20 | ▶ | my $cref = eval "package main; $value" or | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 790 | die "Can't evaluate '$value' ($@)"; | ||||||||||||||||||||||||||||||||||||||||||
| 791 | 19 | return $cref; | |||||||||||||||||||||||||||||||||||||||||
| 792 | } | ||||||||||||||||||||||||||||||||||||||||||
| 793 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 794 | 0 | die "Invalid value for \$Log::Log4perl::Config->allow_code(): '". | |||||||||||||||||||||||||||||||||||||||||
| 795 | Log::Log4perl::Config->allow_code() . "'"; | ||||||||||||||||||||||||||||||||||||||||||
| 796 | } | ||||||||||||||||||||||||||||||||||||||||||
| 797 | } | ||||||||||||||||||||||||||||||||||||||||||
| 798 | |||||||||||||||||||||||||||||||||||||||||||
| 799 | 813 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 800 | } | ||||||||||||||||||||||||||||||||||||||||||
| 801 | |||||||||||||||||||||||||||||||||||||||||||
| 802 | ########################################### | ||||||||||||||||||||||||||||||||||||||||||
| 803 | 7 | ▶ | sub compile_in_safe_cpt { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
compile_in_safe_cpt: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 804 | ########################################### | ||||||||||||||||||||||||||||||||||||||||||
| 805 | 7 | my($value, $allowed_ops) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 806 | |||||||||||||||||||||||||||||||||||||||||||
| 807 | # set up a Safe compartment | ||||||||||||||||||||||||||||||||||||||||||
| 808 | 7 | require Safe; | |||||||||||||||||||||||||||||||||||||||||
| 809 | 7 | my $safe = Safe->new(); | |||||||||||||||||||||||||||||||||||||||||
| 810 | 7 | $safe->permit_only( @{ $allowed_ops } ); | |||||||||||||||||||||||||||||||||||||||||
| 811 | |||||||||||||||||||||||||||||||||||||||||||
| 812 | # share things with the compartment | ||||||||||||||||||||||||||||||||||||||||||
| 813 | 7 | for( sort keys %{ Log::Log4perl::Config->vars_shared_with_safe_compartment() } ) { | |||||||||||||||||||||||||||||||||||||||||
| 814 | 11 | my $toshare = Log::Log4perl::Config->vars_shared_with_safe_compartment($_); | |||||||||||||||||||||||||||||||||||||||||
| 815 | 11 | ▶ | $safe->share_from( $_, $toshare ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 816 | 0 | or die "Can't share @{ $toshare } with Safe compartment"; | |||||||||||||||||||||||||||||||||||||||||
| 817 | } | ||||||||||||||||||||||||||||||||||||||||||
| 818 | |||||||||||||||||||||||||||||||||||||||||||
| 819 | # evaluate with restrictions | ||||||||||||||||||||||||||||||||||||||||||
| 820 | 7 | ▶ | my $cref = $safe->reval("package main; $value") or | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 821 | die "Can't evaluate '$value' in Safe compartment ($@)"; | ||||||||||||||||||||||||||||||||||||||||||
| 822 | 3 | return $cref; | |||||||||||||||||||||||||||||||||||||||||
| 823 | |||||||||||||||||||||||||||||||||||||||||||
| 824 | } | ||||||||||||||||||||||||||||||||||||||||||
| 825 | |||||||||||||||||||||||||||||||||||||||||||
| 826 | ########################################### | ||||||||||||||||||||||||||||||||||||||||||
| 827 | 211 | ▶ | sub boolean_to_perlish { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
boolean_to_perlish: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 828 | ########################################### | ||||||||||||||||||||||||||||||||||||||||||
| 829 | 211 | my($value) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 830 | |||||||||||||||||||||||||||||||||||||||||||
| 831 | # Translate boolean to perlish | ||||||||||||||||||||||||||||||||||||||||||
| 832 | 211 | ▶ | $value = 1 if $value =~ /^true$/i; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 833 | 211 | ▶ | $value = 0 if $value =~ /^false$/i; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 834 | |||||||||||||||||||||||||||||||||||||||||||
| 835 | 211 | return $value; | |||||||||||||||||||||||||||||||||||||||||
| 836 | } | ||||||||||||||||||||||||||||||||||||||||||
| 837 | |||||||||||||||||||||||||||||||||||||||||||
| 838 | ########################################### | ||||||||||||||||||||||||||||||||||||||||||
| 839 | 28 | ▶ | sub vars_shared_with_safe_compartment { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
vars_shared_with_safe_compartment: called CC=8 SCAR=21.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 840 | ########################################### | ||||||||||||||||||||||||||||||||||||||||||
| 841 | 28 | my($class, @args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 842 | |||||||||||||||||||||||||||||||||||||||||||
| 843 | # Allow both for ...::Config::foo() and ...::Config->foo() | ||||||||||||||||||||||||||||||||||||||||||
| 844 | 28 | ▶ | if(defined $class and $class ne __PACKAGE__) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $class and $class ne __PACKAGE__
MC/DC0%0/2
defined $class and $class ne __PACKAGE__
defined $class
$class ne __PACKAGE__
Truth table33%1/3
A and B
A= defined $classB= $class ne __PACKAGE__
| |||||||||||||||||||||||||||||||||||||||||||
| 845 | 0 | unshift @args, $class; | |||||||||||||||||||||||||||||||||||||||||
| 846 | } | ||||||||||||||||||||||||||||||||||||||||||
| 847 | |||||||||||||||||||||||||||||||||||||||||||
| 848 | # handle different invocation styles | ||||||||||||||||||||||||||||||||||||||||||
| 849 | 28 | ▶ | if(@args == 1 && ref $args[0] eq 'HASH' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition100%3/3
@args == 1 and ref $args[0] eq "HASH"
MC/DC100%2/2
@args == 1 and ref $args[0] eq "HASH"
@args == 1
ref $args[0] eq "HASH"
Truth table100%3/3
A and B
A= @args == 1B= ref $args[0] eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||
| 850 | # replace entire hash of vars | ||||||||||||||||||||||||||||||||||||||||||
| 851 | 2 | %Log::Log4perl::VARS_SHARED_WITH_SAFE_COMPARTMENT = %{$args[0]}; | |||||||||||||||||||||||||||||||||||||||||
| 852 | } | ||||||||||||||||||||||||||||||||||||||||||
| 853 | elsif( @args == 1 ) { | ||||||||||||||||||||||||||||||||||||||||||
| 854 | # return vars for given package | ||||||||||||||||||||||||||||||||||||||||||
| 855 | return $Log::Log4perl::VARS_SHARED_WITH_SAFE_COMPARTMENT{ | ||||||||||||||||||||||||||||||||||||||||||
| 856 | 12 | $args[0]}; | |||||||||||||||||||||||||||||||||||||||||
| 857 | } | ||||||||||||||||||||||||||||||||||||||||||
| 858 | elsif( @args == 2 ) { | ||||||||||||||||||||||||||||||||||||||||||
| 859 | # add/replace package/var pair | ||||||||||||||||||||||||||||||||||||||||||
| 860 | $Log::Log4perl::VARS_SHARED_WITH_SAFE_COMPARTMENT{ | ||||||||||||||||||||||||||||||||||||||||||
| 861 | 2 | $args[0]} = $args[1]; | |||||||||||||||||||||||||||||||||||||||||
| 862 | } | ||||||||||||||||||||||||||||||||||||||||||
| 863 | |||||||||||||||||||||||||||||||||||||||||||
| 864 | 16 | ▶ | return wantarray ? %Log::Log4perl::VARS_SHARED_WITH_SAFE_COMPARTMENT | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 865 | : \%Log::Log4perl::VARS_SHARED_WITH_SAFE_COMPARTMENT; | ||||||||||||||||||||||||||||||||||||||||||
| 866 | |||||||||||||||||||||||||||||||||||||||||||
| 867 | } | ||||||||||||||||||||||||||||||||||||||||||
| 868 | |||||||||||||||||||||||||||||||||||||||||||
| 869 | ########################################### | ||||||||||||||||||||||||||||||||||||||||||
| 870 | 28 | ▶ | sub allowed_code_ops { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
allowed_code_ops: called CC=6 SCAR=19.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 871 | ########################################### | ||||||||||||||||||||||||||||||||||||||||||
| 872 | 28 | my($class, @args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 873 | |||||||||||||||||||||||||||||||||||||||||||
| 874 | # Allow both for ...::Config::foo() and ...::Config->foo() | ||||||||||||||||||||||||||||||||||||||||||
| 875 | 28 | ▶ | if(defined $class and $class ne __PACKAGE__) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $class and $class ne __PACKAGE__
MC/DC0%0/2
defined $class and $class ne __PACKAGE__
defined $class
$class ne __PACKAGE__
Truth table33%1/3
A and B
A= defined $classB= $class ne __PACKAGE__
| |||||||||||||||||||||||||||||||||||||||||||
| 876 | 0 | unshift @args, $class; | |||||||||||||||||||||||||||||||||||||||||
| 877 | } | ||||||||||||||||||||||||||||||||||||||||||
| 878 | |||||||||||||||||||||||||||||||||||||||||||
| 879 | 28 | ▶ | if(@args) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 880 | 1 | @Log::Log4perl::ALLOWED_CODE_OPS_IN_CONFIG_FILE = @args; | |||||||||||||||||||||||||||||||||||||||||
| 881 | } | ||||||||||||||||||||||||||||||||||||||||||
| 882 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 883 | # give back 'undef' instead of an empty arrayref | ||||||||||||||||||||||||||||||||||||||||||
| 884 | 27 | ▶ | unless( @Log::Log4perl::ALLOWED_CODE_OPS_IN_CONFIG_FILE ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 885 | 26 | return; | |||||||||||||||||||||||||||||||||||||||||
| 886 | } | ||||||||||||||||||||||||||||||||||||||||||
| 887 | } | ||||||||||||||||||||||||||||||||||||||||||
| 888 | |||||||||||||||||||||||||||||||||||||||||||
| 889 | return wantarray ? @Log::Log4perl::ALLOWED_CODE_OPS_IN_CONFIG_FILE | ||||||||||||||||||||||||||||||||||||||||||
| 890 | 2 | ▶ | : \@Log::Log4perl::ALLOWED_CODE_OPS_IN_CONFIG_FILE; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 891 | } | ||||||||||||||||||||||||||||||||||||||||||
| 892 | |||||||||||||||||||||||||||||||||||||||||||
| 893 | ########################################### | ||||||||||||||||||||||||||||||||||||||||||
| 894 | 35 | ▶ | sub allowed_code_ops_convenience_map { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
allowed_code_ops_convenience_map: called CC=9 SCAR=22.7
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 895 | ########################################### | ||||||||||||||||||||||||||||||||||||||||||
| 896 | 35 | my($class, @args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 897 | |||||||||||||||||||||||||||||||||||||||||||
| 898 | # Allow both for ...::Config::foo() and ...::Config->foo() | ||||||||||||||||||||||||||||||||||||||||||
| 899 | 35 | ▶ | if(defined $class and $class ne __PACKAGE__) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $class and $class ne __PACKAGE__
MC/DC0%0/2
defined $class and $class ne __PACKAGE__
defined $class
$class ne __PACKAGE__
Truth table33%1/3
A and B
A= defined $classB= $class ne __PACKAGE__
| |||||||||||||||||||||||||||||||||||||||||||
| 900 | 0 | unshift @args, $class; | |||||||||||||||||||||||||||||||||||||||||
| 901 | } | ||||||||||||||||||||||||||||||||||||||||||
| 902 | |||||||||||||||||||||||||||||||||||||||||||
| 903 | # handle different invocation styles | ||||||||||||||||||||||||||||||||||||||||||
| 904 | 35 | ▶ | if( @args == 1 && ref $args[0] eq 'HASH' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition100%3/3
@args == 1 and ref $args[0] eq "HASH"
MC/DC100%2/2
@args == 1 and ref $args[0] eq "HASH"
@args == 1
ref $args[0] eq "HASH"
Truth table100%3/3
A and B
A= @args == 1B= ref $args[0] eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||
| 905 | # replace entire map | ||||||||||||||||||||||||||||||||||||||||||
| 906 | 2 | %Log::Log4perl::ALLOWED_CODE_OPS = %{$args[0]}; | |||||||||||||||||||||||||||||||||||||||||
| 907 | } | ||||||||||||||||||||||||||||||||||||||||||
| 908 | elsif( @args == 1 ) { | ||||||||||||||||||||||||||||||||||||||||||
| 909 | # return single opcode mask | ||||||||||||||||||||||||||||||||||||||||||
| 910 | return $Log::Log4perl::ALLOWED_CODE_OPS{ | ||||||||||||||||||||||||||||||||||||||||||
| 911 | 27 | $args[0]}; | |||||||||||||||||||||||||||||||||||||||||
| 912 | } | ||||||||||||||||||||||||||||||||||||||||||
| 913 | elsif( @args == 2 ) { | ||||||||||||||||||||||||||||||||||||||||||
| 914 | # make sure the mask is an array ref | ||||||||||||||||||||||||||||||||||||||||||
| 915 | 1 | ▶ | if( ref $args[1] ne 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 916 | 0 | die "invalid mask (not an array ref) for convenience name '$args[0]'"; | |||||||||||||||||||||||||||||||||||||||||
| 917 | } | ||||||||||||||||||||||||||||||||||||||||||
| 918 | # add name/mask pair | ||||||||||||||||||||||||||||||||||||||||||
| 919 | $Log::Log4perl::ALLOWED_CODE_OPS{ | ||||||||||||||||||||||||||||||||||||||||||
| 920 | 1 | $args[0]} = $args[1]; | |||||||||||||||||||||||||||||||||||||||||
| 921 | } | ||||||||||||||||||||||||||||||||||||||||||
| 922 | |||||||||||||||||||||||||||||||||||||||||||
| 923 | 8 | ▶ | return wantarray ? %Log::Log4perl::ALLOWED_CODE_OPS | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 924 | : \%Log::Log4perl::ALLOWED_CODE_OPS | ||||||||||||||||||||||||||||||||||||||||||
| 925 | } | ||||||||||||||||||||||||||||||||||||||||||
| 926 | |||||||||||||||||||||||||||||||||||||||||||
| 927 | ########################################### | ||||||||||||||||||||||||||||||||||||||||||
| 928 | 89 | ▶ | sub allow_code { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
allow_code: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 929 | ########################################### | ||||||||||||||||||||||||||||||||||||||||||
| 930 | 89 | my($class, @args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 931 | |||||||||||||||||||||||||||||||||||||||||||
| 932 | # Allow both for ...::Config::foo() and ...::Config->foo() | ||||||||||||||||||||||||||||||||||||||||||
| 933 | 89 | ▶ | if(defined $class and $class ne __PACKAGE__) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $class and $class ne __PACKAGE__
MC/DC50%1/2
defined $class and $class ne __PACKAGE__
defined $class
$class ne __PACKAGE__
Truth table66%2/3
A and B
A= defined $classB= $class ne __PACKAGE__
| |||||||||||||||||||||||||||||||||||||||||||
| 934 | 9 | unshift @args, $class; | |||||||||||||||||||||||||||||||||||||||||
| 935 | } | ||||||||||||||||||||||||||||||||||||||||||
| 936 | |||||||||||||||||||||||||||||||||||||||||||
| 937 | 89 | ▶ | if(@args) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 938 | 14 | $Log::Log4perl::ALLOW_CODE_IN_CONFIG_FILE = | |||||||||||||||||||||||||||||||||||||||||
| 939 | $args[0]; | ||||||||||||||||||||||||||||||||||||||||||
| 940 | } | ||||||||||||||||||||||||||||||||||||||||||
| 941 | |||||||||||||||||||||||||||||||||||||||||||
| 942 | 89 | return $Log::Log4perl::ALLOW_CODE_IN_CONFIG_FILE; | |||||||||||||||||||||||||||||||||||||||||
| 943 | } | ||||||||||||||||||||||||||||||||||||||||||
| 944 | |||||||||||||||||||||||||||||||||||||||||||
| 945 | ################################################ | ||||||||||||||||||||||||||||||||||||||||||
| 946 | 14 | ▶ | sub var_subst { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
var_subst: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 947 | ################################################ | ||||||||||||||||||||||||||||||||||||||||||
| 948 | 14 | my($varname, $subst_hash) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 949 | |||||||||||||||||||||||||||||||||||||||||||
| 950 | # Throw out blanks | ||||||||||||||||||||||||||||||||||||||||||
| 951 | 14 | $varname =~ s/\s+//g; | |||||||||||||||||||||||||||||||||||||||||
| 952 | |||||||||||||||||||||||||||||||||||||||||||
| 953 | 14 | ▶ | if(exists $subst_hash->{$varname}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 954 | 9 | print "Replacing variable: '$varname' => '$subst_hash->{$varname}'\n" | |||||||||||||||||||||||||||||||||||||||||
| 955 | if _INTERNAL_DEBUG; | ||||||||||||||||||||||||||||||||||||||||||
| 956 | 9 | return $subst_hash->{$varname}; | |||||||||||||||||||||||||||||||||||||||||
| 957 | |||||||||||||||||||||||||||||||||||||||||||
| 958 | } elsif(exists $ENV{$varname}) { | ||||||||||||||||||||||||||||||||||||||||||
| 959 | 4 | print "Replacing ENV variable: '$varname' => '$ENV{$varname}'\n" | |||||||||||||||||||||||||||||||||||||||||
| 960 | if _INTERNAL_DEBUG; | ||||||||||||||||||||||||||||||||||||||||||
| 961 | 4 | return $ENV{$varname}; | |||||||||||||||||||||||||||||||||||||||||
| 962 | |||||||||||||||||||||||||||||||||||||||||||
| 963 | } | ||||||||||||||||||||||||||||||||||||||||||
| 964 | |||||||||||||||||||||||||||||||||||||||||||
| 965 | 1 | die "Undefined Variable '$varname'"; | |||||||||||||||||||||||||||||||||||||||||
| 966 | } | ||||||||||||||||||||||||||||||||||||||||||
| 967 | |||||||||||||||||||||||||||||||||||||||||||
| 968 | 54 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 969 | |||||||||||||||||||||||||||||||||||||||||||
| 970 | __END__ | ||||||||||||||||||||||||||||||||||||||||||