| 1 | package Su::Log; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 26 | ▶ | use Test::More; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 26 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 26 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | =pod | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | Su::Log - A simple Logger which filters output by log level and regexp of the target class name. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | =head1 SYNOPSYS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | my $log = Su::Log->new; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | $log->info("info message."); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | # Set the log level to output. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | Su::Log->set_level("trace"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | $log->trace("trace message."); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | # Disable logging and nothing output. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | $log->off(__PACKAGE__); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | $log->info("info message."); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | # Clear the logging state. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | $log->clear(__PACKAGE__); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | # Enable logging. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | $log->on(__PACKAGE__); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | $log->info("info message."); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | # Clear the logging state. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | $log->clear(__PACKAGE__); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | # Set the logging target and log level. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | $log->on( 'Pkg::LogTarget', 'error' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | # Set the logging target by regex. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | $log->on( qr/Pkg::.*/, 'error' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | # Clear the logging state. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | $log->clear(qr/Pkg::.*/); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | # Output logs to the file. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | $log->log_handler('path/to/logfile'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | Su::Log is a simple Logger module. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | Su::Log has the following features. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | =over | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | =item Narrow down the output by log level. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | =item Narrow down the logging target class. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | =item Narrow down the output by customized log kind. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | =item Customize the log handler function. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | =head1 FUNCTIONS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | =over | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | # Each elements consist of { class => $class, level => $level } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 26 | our @target_class = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 26 | our @target_tag = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | # Default log level. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 26 | our $level = "info"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | # User specified global log level. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 26 | our $global_log_level; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | # Elements are String or Regexp of the target class. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 26 | our @exclusion_class = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | # If you want to use this Log class not as oblect oriented style, but | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | # as function style directly, set current class name to this variable. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 26 | our $class_name; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 26 | our $all_on = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 26 | our $all_off = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 26 | our $log_handler; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | BEGIN: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | # Set default handler. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 26 | $log_handler = | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 37 | ▶ | sub { my $msg = _make_log_string(@_); print $msg; return $msg; }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | } ## end BEGIN: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 26 | my $level_hash = { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | debug => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | trace => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | info => 2, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | warn => 3, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | error => 4, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | crit => 5, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | =item on() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | Add the passed module name to the list of the logging tareget. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | If the parameter is not passed, then set the whole class as logging | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | target. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | # NOTE: @target_class is a package variable, so shared with other | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | # logger even if you call this method via the specific logger | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | # instance. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 9 | ▶ | sub on { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
on: called CC=6 SCAR=26.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | ▶ | my $self = shift if ( $_[0] eq __PACKAGE__ || ref $_[0] eq __PACKAGE__ ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
on: not called CC=6 SCAR=26.1
Pod
documented
Branch: 2 branches
Condition33%2/6
$_[0] eq __PACKAGE__ or ref $_[0] eq __PACKAGE__
$_[0] eq __PACKAGE__ or ref $_[0] eq __PACKAGE__
MC/DC0%0/2
$_[0] eq __PACKAGE__ or ref $_[0] eq __PACKAGE__
$_[0] eq __PACKAGE__
ref $_[0] eq __PACKAGE__
MC/DC0%0/2
$_[0] eq __PACKAGE__ or ref $_[0] eq __PACKAGE__
$_[0] eq __PACKAGE__
ref $_[0] eq __PACKAGE__
Truth table66%2/3
A or B
A= $_[0] eq __PACKAGE__B= ref $_[0] eq __PACKAGE__
Truth table0%0/3
A or B
A= $_[0] eq __PACKAGE__B= ref $_[0] eq __PACKAGE__
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | my $level = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | ▶ | if ($class) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | # diag( "on|" . $class . "|" . $level ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | # Remove old entry before adding new one. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 0 | ▶ | if ( grep { $_->{class} =~ /^$class$/ } @target_class ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | # @target_class = grep { $_->{class} ne /^$class$/ } @target_class; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 0 | @target_class = grep { $_->{class} !~ /^$class$/ } @target_class; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 0 | push @target_class, { class => $class, level => $level }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | my $bRegex = ref $class eq 'Regexp'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | ▶ | if ($bRegex) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 0 | @exclusion_class = grep { $_ ne $class } @exclusion_class; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | @exclusion_class = grep !/^$class$/, @exclusion_class; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | $self->{on} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | } ## end sub on | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | =item enable() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | This method force enable the logging regardless of whether the logging | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | of the target class is enabled or disabled. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | Internally, this method set the $all_on flag on, and $all_off flag | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | off. To clear this state, call the method L<Su::clear_all_flags>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 2 | ▶ | sub enable { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
enable: called CC=1 SCAR=1.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | ▶ | $all_on = 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
enable: not called CC=1 SCAR=1.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 0 | $all_off = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | =item off() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | Disable the logging of the class which name is passed as a parameter. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | $log->off('Target::Class'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | If the parameter is omitted, this effects only own instance. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | $log->off; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 13 | ▶ | sub off { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
off: called CC=8 SCAR=31.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 0 | ▶ | my $self = shift if ( $_[0] eq __PACKAGE__ || ref $_[0] eq __PACKAGE__ ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
off: not called CC=8 SCAR=31.5
Pod
documented
Branch: 2 branches
Condition33%2/6
$_[0] eq __PACKAGE__ or ref $_[0] eq __PACKAGE__
$_[0] eq __PACKAGE__ or ref $_[0] eq __PACKAGE__
MC/DC0%0/2
$_[0] eq __PACKAGE__ or ref $_[0] eq __PACKAGE__
$_[0] eq __PACKAGE__
ref $_[0] eq __PACKAGE__
MC/DC0%0/2
$_[0] eq __PACKAGE__ or ref $_[0] eq __PACKAGE__
$_[0] eq __PACKAGE__
ref $_[0] eq __PACKAGE__
Truth table66%2/3
A or B
A= $_[0] eq __PACKAGE__B= ref $_[0] eq __PACKAGE__
Truth table0%0/3
A or B
A= $_[0] eq __PACKAGE__B= ref $_[0] eq __PACKAGE__
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 0 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | # In case of specified the log target. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | ▶ | if ($class) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | # String parameter. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 0 | ▶ | if ( !ref $class ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 0 | ▶ | unless ( grep /^$class$/, @exclusion_class ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 0 | push @exclusion_class, $class; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | # Remove the passed class name from log target classes. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | @target_class = grep { $_->{class} !~ /^$class$/ } @target_class; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | } ## end if ( !ref $class ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | elsif ( ref $class eq 'Regexp' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 0 | ▶ | unless ( grep { $_ eq $class } @exclusion_class ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 0 | push @exclusion_class, $class; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | # Remove the passed regex from the log tareget classes. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 0 | @target_class = grep { $class ne $_->{class} } @target_class; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | } ## end elsif ( ref $class eq 'Regexp') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | } ## end if ($class) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | # diag("off the logging of this instance."); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | # Instance parameter effects only own instance. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 0 | $self->{on} = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | } ## end else [ if ($class) ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | } ## end sub off | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | =item disable() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | This method force disable the logging regardless of whether the logging | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | of the target class is enabled or disabled. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | Internally, ths method set the $all_off flag on, and $all_on flag off. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | To clear this state, call the method L<Su::clear_all_flags>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 1 | ▶ | sub disable { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
disable: called CC=1 SCAR=1.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 0 | ▶ | $all_off = 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
disable: not called CC=1 SCAR=1.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 0 | $all_on = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | } ## end sub disable | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | =item clear_all_flags() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | Clear C<$all_on> and C<$all_off> flags that is set by L<Su::enable> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | or L<Su::disable> method. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 8 | ▶ | sub clear_all_flags { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
clear_all_flags: called CC=1 SCAR=1.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 0 | ▶ | $all_on = 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
clear_all_flags: not called CC=1 SCAR=1.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | $all_off = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | =item clear() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | If the parameter is passed, This method clear the state of the passed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | target that is set by the method L<on> and L<off>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | If the parameter is omitted, then clear all of the log settings. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 7 | ▶ | sub clear { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
clear: called CC=5 SCAR=21.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 0 | ▶ | my $self = shift if ( ref $_[0] eq __PACKAGE__ || $_[0] eq __PACKAGE__ ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
clear: not called CC=5 SCAR=21.9
Pod
documented
Branch: 2 branches
Condition33%2/6
ref $_[0] eq __PACKAGE__ or $_[0] eq __PACKAGE__
ref $_[0] eq __PACKAGE__ or $_[0] eq __PACKAGE__
MC/DC0%0/2
ref $_[0] eq __PACKAGE__ or $_[0] eq __PACKAGE__
ref $_[0] eq __PACKAGE__
$_[0] eq __PACKAGE__
MC/DC0%0/2
ref $_[0] eq __PACKAGE__ or $_[0] eq __PACKAGE__
ref $_[0] eq __PACKAGE__
$_[0] eq __PACKAGE__
Truth table66%2/3
A or B
A= ref $_[0] eq __PACKAGE__B= $_[0] eq __PACKAGE__
Truth table0%0/3
A or B
A= ref $_[0] eq __PACKAGE__B= $_[0] eq __PACKAGE__
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 0 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | # Remove the specified expression. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 0 | ▶ | if ($class) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 0 | my $bRegex = ref $class eq 'Regexp'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 0 | ▶ | if ($bRegex) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 0 | @target_class = grep { $class ne $_->{class} } @target_class; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 0 | @exclusion_class = grep { $_ ne $class } @exclusion_class; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 0 | @target_class = grep { $_->{class} !~ /^$class$/ } @target_class; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 0 | @exclusion_class = grep !/^$class$/, @exclusion_class; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | # Clear all condition. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 0 | @target_class = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 0 | @target_tag = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 0 | @exclusion_class = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 0 | clear_all_flags(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | } ## end else [ if ($class) ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | } ## end sub clear | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | =item tag_on() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | Add the passed tag to the target tags list. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 0 | ▶ | sub tag_on { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
tag_on: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 0 | ▶ | shift if ( $_[0] eq __PACKAGE__ ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
tag_on: not called CC=2 SCAR=17.9
Pod
documented
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 0 | my $tag = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 0 | push @target_tag, $tag; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | =item tag_off() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | Remove the passed tag from the target tags list. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 0 | ▶ | sub tag_off { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
tag_off: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 0 | ▶ | shift if ( $_[0] eq __PACKAGE__ ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
tag_off: not called CC=2 SCAR=17.9
Pod
documented
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 0 | my $tag = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 0 | @target_tag = grep !/^$tag$/, @target_tag; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | =item new() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | Constructor. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | my $log = new Su::Log->new; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | my $log = new Su::Log->new($self); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | my $log = new Su::Log->new('PKG::TargetClass'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | Instantiate the Logger class. The passed instance or the string of the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | module name is registered as a logging target class. If the parameter | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | is omitted, then the caller is registered automatically. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 163 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=4 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=4 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 0 | ▶ | $self = ref $self if ( ref $self ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 0 | my $target_class = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | # If passed argment is a reference of the instance, then extract class name. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 0 | my $class_name = ref $target_class; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | # Else, use passed string as class name. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 0 | ▶ | if ( !$class_name ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 0 | $class_name = $target_class; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 0 | ▶ | if ( !$class_name ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 0 | $class_name = caller(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | # diag("classname:" . $class_name); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | # diag( Dumper($class_name)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | # Su::Log->trace( "classname:" . $class_name ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | # Su::Log->trace( Dumper($class_name) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | # Add the caller class to the target list automatically. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 0 | return bless { class_name => $class_name, on => 1, level => $level }, $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | } ## end sub new | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | =item is_target() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | Determine whether the module is a logging target or not. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | 2537 | ▶ | sub is_target { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_target: called CC=9 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_target: not called CC=9 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 0 | ▶ | if ($all_on) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 0 | return { is_target => 1, has_level => undef }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | } elsif ($all_off) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 0 | return { is_target => 0, has_level => undef }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 0 | my $self_class_name = $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 0 | ▶ | if ( ref $self ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 0 | ▶ | $self_class_name = $self->{class_name} ? $self->{class_name} : $class_name; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | #diag("check classname:" . $self->{class_name}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | # if(! defined($self->{class_name})){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | # die "Class name not passed to the log instance."; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | # } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | #NOTE:Can not trace via trace or something Log class provide. Because recurssion occurs. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | #diag( @target_class); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | # diag("grep result:" . (grep /^$self->{class_name}$/, @target_class)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | # if (index($self->{class_name}, @target_class) != -1){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | # diag( "exc cls:" . Dumper(@exclusion_class) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 0 | ▶ | if ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | grep { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | 0 | ▶ | ref $_ eq 'Regexp' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | ? $self_class_name =~ /$_/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | : $self_class_name =~ /^$_$/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | } @exclusion_class | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | } elsif ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | my @info = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | grep { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | 0 | my $bRegex = ref $_->{class} eq 'Regexp'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | 0 | ▶ | if ($bRegex) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | # diag('use regex'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | # Use class field as regexp. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | 0 | $self_class_name =~ /$_->{class}/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | # diag('use str'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | # Use class field as string,directly. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | 0 | $self_class_name =~ /^$_->{class}$/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | } ## end else [ if ($bRegex) ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | } @target_class | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | # diag( Dumper(@target_class) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | # diag("here2:$info[0]->{class} --- $info[0]->{level}"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | 0 | return { is_target => 1, has_level => 1, level => $info[0]->{level} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | # diag( "here3:" . $self . $self->{on} ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | # Return the instance flag. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | # return $self->{on}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | 0 | return { is_target => $self->{on}, has_level => undef }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | } ## end else [ if ($bRegex) ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | } ## end sub is_target | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | =item set_level() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | Su::Log->set_level("trace"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | Set the log level which effects instance scope. Default level is B<info>; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | 2 | ▶ | sub set_level { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_level: called CC=4 SCAR=21.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | # The first argment may be reference of object or string of class name. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | 0 | ▶ | my $self = shift if ( ref $_[0] eq __PACKAGE__ || $_[0] eq __PACKAGE__ ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_level: not called CC=4 SCAR=21.7
Pod
documented
Branch: 2 branches
Condition16%1/6
ref $_[0] eq __PACKAGE__ or $_[0] eq __PACKAGE__
ref $_[0] eq __PACKAGE__ or $_[0] eq __PACKAGE__
MC/DC0%0/2
ref $_[0] eq __PACKAGE__ or $_[0] eq __PACKAGE__
ref $_[0] eq __PACKAGE__
$_[0] eq __PACKAGE__
MC/DC0%0/2
ref $_[0] eq __PACKAGE__ or $_[0] eq __PACKAGE__
ref $_[0] eq __PACKAGE__
$_[0] eq __PACKAGE__
Truth table33%1/3
A or B
A= ref $_[0] eq __PACKAGE__B= $_[0] eq __PACKAGE__
Truth table0%0/3
A or B
A= ref $_[0] eq __PACKAGE__B= $_[0] eq __PACKAGE__
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | 0 | my $passed_level = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | croak "Passed log level is invalid:" . $passed_level | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | 0 | ▶ | if !grep /^$passed_level$/, keys %{$level_hash}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | 0 | $self->{level} = $passed_level; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | } ## end sub set_level | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | =item set_global_log_level() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | Su::Log->set_default_log_level("trace"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | Set the log level. This setting effects as the package scope variable. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | To clear the $global_log_level flag, pass undef to this method. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | 5 | ▶ | sub set_global_log_level { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_global_log_level: called CC=5 SCAR=24.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | # The first argment may be reference of object or string of class name. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | 0 | ▶ | shift if ( ref $_[0] eq __PACKAGE__ || $_[0] eq __PACKAGE__ ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_global_log_level: not called CC=5 SCAR=24.3
Pod
documented
Branch: 2 branches
Condition33%2/6
ref $_[0] eq __PACKAGE__ or $_[0] eq __PACKAGE__
ref $_[0] eq __PACKAGE__ or $_[0] eq __PACKAGE__
MC/DC0%0/2
ref $_[0] eq __PACKAGE__ or $_[0] eq __PACKAGE__
ref $_[0] eq __PACKAGE__
$_[0] eq __PACKAGE__
MC/DC0%0/2
ref $_[0] eq __PACKAGE__ or $_[0] eq __PACKAGE__
ref $_[0] eq __PACKAGE__
$_[0] eq __PACKAGE__
Truth table66%2/3
A or B
A= ref $_[0] eq __PACKAGE__B= $_[0] eq __PACKAGE__
Truth table0%0/3
A or B
A= ref $_[0] eq __PACKAGE__B= $_[0] eq __PACKAGE__
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | 0 | my $passed_level = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | croak "Passed log level is invalid:" . $passed_level | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | 0 | ▶ | if defined $passed_level && !grep /^$passed_level$/, keys %{$level_hash}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%2/6
defined $passed_level and not grep(/^$passed_level$/, keys %{$level_hash;})
defined $passed_level and not grep(/^$passed_level$/, keys %{$level_hash;})
MC/DC0%0/2
defined $passed_level and not grep(/^$passed_level$/, keys %{$level_hash;})
defined $passed_level
not grep(/^$passed_level$/, keys %{$level_hash;})
MC/DC0%0/2
defined $passed_level and not grep(/^$passed_level$/, keys %{$level_hash;})
defined $passed_level
not grep(/^$passed_level$/, keys %{$level_hash;})
Truth table66%2/3
A and not(B)
A= defined $passed_levelB= not grep(/^$passed_level$/, keys %{$level_hash;})
Truth table0%0/3
A and not(B)
A= defined $passed_levelB= not grep(/^$passed_level$/, keys %{$level_hash;})
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | 0 | $global_log_level = $passed_level; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | } ## end sub set_global_log_level | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | =item is_large_level() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | Return whether the passed log level is larger than the current log level or not. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | If the second parameter is passed, then compare that value as the current log level. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | 73 | ▶ | sub is_large_level { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_large_level: called CC=7 SCAR=28.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | 0 | ▶ | my $self = shift if ( ref $_[0] eq __PACKAGE__ ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_large_level: not called CC=7 SCAR=28.4
Pod
documented
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | 0 | ▶ | $self = caller() unless $self; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | # diag "dumper:" . Dumper( $self->{class_name} ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | 0 | my $arg = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | #NOTE:Can not trace via trace command which Log class provides, because recursion occurs. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | #diag("compare:" . $arg . ":" . $level); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | 0 | my $compare_target_level = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | # If the second parameter is passed, use it as compare target directly. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | 0 | ▶ | unless ($compare_target_level) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | 0 | ▶ | if ( defined $global_log_level ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | 0 | $compare_target_level = $global_log_level; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | } elsif ( $self->{level} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | 0 | $compare_target_level = $self->{level}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | 0 | $compare_target_level = $level; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | } ## end unless ($compare_target_level) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | # diag "[TRACE]compare_target_level:$compare_target_level:arg:$arg\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | 0 | ▶ | return $level_hash->{$arg} >= $level_hash->{$compare_target_level} ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | } ## end sub is_large_level | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | 2537 | ▶ | sub _log_method_impl { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_log_method_impl: called CC=6 SCAR=23.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | 0 | ▶ | my $self = shift if ( ref $_[0] eq __PACKAGE__ ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_log_method_impl: not called CC=6 SCAR=23.5
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | 0 | my $opt_href = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | 0 | my $caller_prefix = $opt_href->{caller}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | 0 | my $method_level = $opt_href->{level}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | 0 | ▶ | my $log_handler = $self->{log_handler} ? $self->{log_handler} : $log_handler; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | 0 | ▶ | my $target_info = is_target( _is_empty($self) ? caller() : $self ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | 0 | ▶ | if ( $target_info->{is_target} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition50%3/6
$target_info->{"is_target"} and $self->is_large_level($method_level, $target_info->{"level"})
$target_info->{"is_target"} and $self->is_large_level($method_level, $target_info->{"level"})
MC/DC100%2/2
$target_info->{"is_target"} and $self->is_large_level($method_level, $target_info->{"level"})
$target_info->{"is_target"}
$self->is_large_level($method_level, $target_info->{"level"})
MC/DC0%0/2
$target_info->{"is_target"} and $self->is_large_level($method_level, $target_info->{"level"})
$target_info->{"is_target"}
$self->is_large_level($method_level, $target_info->{"level"})
Truth table100%3/3
A and B
A= $target_info->{"is_target"}B= $self->is_large_level($method_level, $target_info->{"level"})
Truth table0%0/3
A and B
A= $target_info->{"is_target"}B= $self->is_large_level($method_level, $target_info->{"level"})
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | && $self->is_large_level( $method_level, $target_info->{level} ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | 0 | return $log_handler->( "[$caller_prefix]", uc("[$method_level]"), @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | } ## end sub _log_method_impl | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | =item trace() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | Log the passed message as trace level. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | 2480 | ▶ | sub trace { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
trace: called CC=3 SCAR=16.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | 0 | ▶ | my $self = shift if ( ref $_[0] eq __PACKAGE__ || $_[0] eq __PACKAGE__ ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
trace: not called CC=3 SCAR=16.2
Pod
documented
Branch: 2 branches
Condition33%2/6
ref $_[0] eq __PACKAGE__ or $_[0] eq __PACKAGE__
ref $_[0] eq __PACKAGE__ or $_[0] eq __PACKAGE__
MC/DC0%0/2
ref $_[0] eq __PACKAGE__ or $_[0] eq __PACKAGE__
ref $_[0] eq __PACKAGE__
$_[0] eq __PACKAGE__
MC/DC0%0/2
ref $_[0] eq __PACKAGE__ or $_[0] eq __PACKAGE__
ref $_[0] eq __PACKAGE__
$_[0] eq __PACKAGE__
Truth table66%2/3
A or B
A= ref $_[0] eq __PACKAGE__B= $_[0] eq __PACKAGE__
Truth table0%0/3
A or B
A= ref $_[0] eq __PACKAGE__B= $_[0] eq __PACKAGE__
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | 0 | my ( $pkg, $file, $line ) = caller; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | 0 | my $caller_prefix = $file . ':L' . $line; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | 0 | $self->_log_method_impl( { caller => $caller_prefix, level => "trace" }, @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | } ## end sub trace | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | =item info() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | Log the passed message as info level. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | 42 | ▶ | sub info { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
info: called CC=3 SCAR=17.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | 0 | ▶ | my $self = shift if ( ref $_[0] eq __PACKAGE__ || $_[0] eq __PACKAGE__ ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
info: not called CC=3 SCAR=17.3
Pod
documented
Branch: 2 branches
Condition16%1/6
ref $_[0] eq __PACKAGE__ or $_[0] eq __PACKAGE__
ref $_[0] eq __PACKAGE__ or $_[0] eq __PACKAGE__
MC/DC0%0/2
ref $_[0] eq __PACKAGE__ or $_[0] eq __PACKAGE__
ref $_[0] eq __PACKAGE__
$_[0] eq __PACKAGE__
MC/DC0%0/2
ref $_[0] eq __PACKAGE__ or $_[0] eq __PACKAGE__
ref $_[0] eq __PACKAGE__
$_[0] eq __PACKAGE__
Truth table33%1/3
A or B
A= ref $_[0] eq __PACKAGE__B= $_[0] eq __PACKAGE__
Truth table0%0/3
A or B
A= ref $_[0] eq __PACKAGE__B= $_[0] eq __PACKAGE__
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | 0 | my ( $pkg, $file, $line ) = caller; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | 0 | my $caller_prefix = $file . ':L' . $line; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | 0 | $self->_log_method_impl( { caller => $caller_prefix, level => "info" }, @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | } ## end sub info | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | =item warn() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | Log the passed message as warn level. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | 3 | ▶ | sub warn { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
warn: called CC=3 SCAR=17.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | 0 | ▶ | my $self = shift if ( ref $_[0] eq __PACKAGE__ || $_[0] eq __PACKAGE__ ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
warn: not called CC=3 SCAR=17.3
Pod
documented
Branch: 2 branches
Condition16%1/6
ref $_[0] eq __PACKAGE__ or $_[0] eq __PACKAGE__
ref $_[0] eq __PACKAGE__ or $_[0] eq __PACKAGE__
MC/DC0%0/2
ref $_[0] eq __PACKAGE__ or $_[0] eq __PACKAGE__
ref $_[0] eq __PACKAGE__
$_[0] eq __PACKAGE__
MC/DC0%0/2
ref $_[0] eq __PACKAGE__ or $_[0] eq __PACKAGE__
ref $_[0] eq __PACKAGE__
$_[0] eq __PACKAGE__
Truth table33%1/3
A or B
A= ref $_[0] eq __PACKAGE__B= $_[0] eq __PACKAGE__
Truth table0%0/3
A or B
A= ref $_[0] eq __PACKAGE__B= $_[0] eq __PACKAGE__
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | 0 | my ( $pkg, $file, $line ) = caller; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | 0 | my $caller_prefix = $file . ':L' . $line; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | 0 | $self->_log_method_impl( { caller => $caller_prefix, level => "warn" }, @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | } ## end sub warn | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | =item error() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | Log the passed message as error level. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 552 | 4 | ▶ | sub error { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
error: called CC=3 SCAR=17.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 553 | 0 | ▶ | my $self = shift if ( ref $_[0] eq __PACKAGE__ || $_[0] eq __PACKAGE__ ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
error: not called CC=3 SCAR=17.3
Pod
documented
Branch: 2 branches
Condition16%1/6
ref $_[0] eq __PACKAGE__ or $_[0] eq __PACKAGE__
ref $_[0] eq __PACKAGE__ or $_[0] eq __PACKAGE__
MC/DC0%0/2
ref $_[0] eq __PACKAGE__ or $_[0] eq __PACKAGE__
ref $_[0] eq __PACKAGE__
$_[0] eq __PACKAGE__
MC/DC0%0/2
ref $_[0] eq __PACKAGE__ or $_[0] eq __PACKAGE__
ref $_[0] eq __PACKAGE__
$_[0] eq __PACKAGE__
Truth table33%1/3
A or B
A= ref $_[0] eq __PACKAGE__B= $_[0] eq __PACKAGE__
Truth table0%0/3
A or B
A= ref $_[0] eq __PACKAGE__B= $_[0] eq __PACKAGE__
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 554 | 0 | my ( $pkg, $file, $line ) = caller; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 555 | 0 | my $caller_prefix = $file . ':L' . $line; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 556 | 0 | $self->_log_method_impl( { caller => $caller_prefix, level => "error" }, @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 557 | } ## end sub error | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 558 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 559 | =item crit() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 560 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 561 | Log the passed message as crit level. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 562 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 563 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 564 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 565 | 4 | ▶ | sub crit { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
crit: called CC=3 SCAR=17.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 566 | 0 | ▶ | my $self = shift if ( ref $_[0] eq __PACKAGE__ || $_[0] eq __PACKAGE__ ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
crit: not called CC=3 SCAR=17.3
Pod
documented
Branch: 2 branches
Condition16%1/6
ref $_[0] eq __PACKAGE__ or $_[0] eq __PACKAGE__
ref $_[0] eq __PACKAGE__ or $_[0] eq __PACKAGE__
MC/DC0%0/2
ref $_[0] eq __PACKAGE__ or $_[0] eq __PACKAGE__
ref $_[0] eq __PACKAGE__
$_[0] eq __PACKAGE__
MC/DC0%0/2
ref $_[0] eq __PACKAGE__ or $_[0] eq __PACKAGE__
ref $_[0] eq __PACKAGE__
$_[0] eq __PACKAGE__
Truth table33%1/3
A or B
A= ref $_[0] eq __PACKAGE__B= $_[0] eq __PACKAGE__
Truth table0%0/3
A or B
A= ref $_[0] eq __PACKAGE__B= $_[0] eq __PACKAGE__
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 567 | 0 | my ( $pkg, $file, $line ) = caller; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 568 | 0 | my $caller_prefix = $file . ':L' . $line; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 569 | 0 | $self->_log_method_impl( { caller => $caller_prefix, level => "crit" }, @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 570 | } ## end sub crit | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 571 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 572 | =item debug() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 573 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 574 | Log the passed message as debug level. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 575 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 576 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 577 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 578 | 4 | ▶ | sub debug { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
debug: called CC=3 SCAR=17.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 579 | 0 | ▶ | my $self = shift if ( ref $_[0] eq __PACKAGE__ || $_[0] eq __PACKAGE__ ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
debug: not called CC=3 SCAR=17.3
Pod
documented
Branch: 2 branches
Condition16%1/6
ref $_[0] eq __PACKAGE__ or $_[0] eq __PACKAGE__
ref $_[0] eq __PACKAGE__ or $_[0] eq __PACKAGE__
MC/DC0%0/2
ref $_[0] eq __PACKAGE__ or $_[0] eq __PACKAGE__
ref $_[0] eq __PACKAGE__
$_[0] eq __PACKAGE__
MC/DC0%0/2
ref $_[0] eq __PACKAGE__ or $_[0] eq __PACKAGE__
ref $_[0] eq __PACKAGE__
$_[0] eq __PACKAGE__
Truth table33%1/3
A or B
A= ref $_[0] eq __PACKAGE__B= $_[0] eq __PACKAGE__
Truth table0%0/3
A or B
A= ref $_[0] eq __PACKAGE__B= $_[0] eq __PACKAGE__
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 580 | 0 | my ( $pkg, $file, $line ) = caller; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 581 | 0 | my $caller_prefix = $file . ':L' . $line; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 582 | 0 | $self->_log_method_impl( { caller => $caller_prefix, level => "debug" }, @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 583 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 584 | } ## end sub debug | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 585 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 586 | =item log() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 587 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 588 | Log the message with the passed tag, if the passed tag is active. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 589 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 590 | my $log = Su::Log->new($self); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 591 | $log->log("some_tag","some message"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 592 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 593 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 594 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 595 | 0 | ▶ | sub log { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
log: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 596 | 0 | ▶ | my $self = shift if ( ref $_[0] eq __PACKAGE__ ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
log: not called CC=6 SCAR=37.4
Pod
documented
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 597 | 0 | my $tag = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 598 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 599 | 0 | ▶ | my $log_handler = $self->{log_handler} ? $self->{log_handler} : $log_handler; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 600 | 0 | ▶ | if ( is_target( _is_empty($self) ? caller() : $self ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
Condition0%0/6
is_target(_is_empty($self) ? caller() : $self) and grep /^$tag$/, @target_tag
is_target(_is_empty($self) ? caller() : $self) and grep /^$tag$/, @target_tag
MC/DC0%0/2
is_target(_is_empty($self) ? caller() : $self) and grep /^$tag$/, @target_tag
is_target(_is_empty($self) ? caller() : $self)
grep /^$tag$/, @target_tag
MC/DC0%0/2
is_target(_is_empty($self) ? caller() : $self) and grep /^$tag$/, @target_tag
is_target(_is_empty($self) ? caller() : $self)
grep /^$tag$/, @target_tag
Truth table0%0/3
A and B
A= is_target(_is_empty($self) ? caller() : $self)B= grep /^$tag$/, @target_tag
Truth table0%0/3
A and B
A= is_target(_is_empty($self) ? caller() : $self)B= grep /^$tag$/, @target_tag
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 601 | && ( grep /^$tag$/, @target_tag ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 602 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 603 | 0 | my ( $pkg, $file, $line ) = caller; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 604 | 0 | my $caller_prefix = $file . ':L' . $line; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 605 | 0 | return $log_handler->( "[$caller_prefix]", "[$tag]", @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 606 | } ## end if ( is_target( _is_empty...)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 607 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 608 | } ## end sub log | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 609 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 610 | =item log_handler() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 611 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 612 | Set the passed method as the log handler of L<Su::Log|Su::Log>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 613 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 614 | $log->log_handler(\&hndl); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 615 | $log->info("info message"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 616 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 617 | sub hndl{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 618 | print(join 'custom log handler:', @_); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 619 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 620 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 621 | $log->log_handler( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 622 | sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 623 | my $level = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 624 | my $msg = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 625 | print $F $level . join( ' ', @_ ) . "\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 626 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 627 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 628 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 629 | If the passed parameter is string, then automatically the handler is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 630 | set to output log to the passed file name. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 631 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 632 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 633 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 634 | 1 | ▶ | sub log_handler { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
log_handler: called CC=6 SCAR=30.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 635 | 0 | ▶ | my $self = shift if ( ref $_[0] eq __PACKAGE__ ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
log_handler: not called CC=6 SCAR=30.9
Pod
documented
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 636 | 0 | my $handler = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 637 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 638 | # Work as setter method. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 639 | 0 | ▶ | if ($handler) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 640 | 0 | ▶ | if ($self) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 641 | 0 | ▶ | if ( ref $handler eq 'CODE' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 642 | 0 | $self->{log_handler} = $handler; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 643 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 644 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 645 | # $handler is passed as log file name. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 646 | 0 | $self->{log_handler} = _make_default_log_file_handler($handler); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 647 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 648 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 649 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 650 | # $log_handler = $handler; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 651 | 0 | ▶ | if ( ref $handler eq 'CODE' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 652 | 0 | $log_handler = $handler; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 653 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 654 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 655 | # $handler is passed as log file name. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 656 | 0 | $log_handler = _make_default_log_file_handler($handler); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 657 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 658 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 659 | } ## end else [ if ($self) ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 660 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 661 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 662 | # The param is omitted, just work as a getter method. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 663 | 0 | return $log_handler; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 664 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 665 | } ## end sub log_handler | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 666 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 667 | =begin comment | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 668 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 669 | Return the handler to output log to the log file. Passed parameter is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 670 | a log file name. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 671 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 672 | =end comment | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 673 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 674 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 675 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 676 | 0 | ▶ | sub _make_default_log_file_handler { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_make_default_log_file_handler: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 677 | 0 | ▶ | my $self = shift if ( ref $_[0] eq __PACKAGE__ ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_make_default_log_file_handler: not called CC=3 SCAR=24.8
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 678 | 0 | my $log_file_name = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 679 | 0 | ▶ | open( my $F, '>>', $log_file_name ) or die $!; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 680 | 0 | ▶ | return sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 681 | 0 | ▶ | my $level = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 682 | 0 | my $msg = _make_log_string(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 683 | 0 | print $F $level . $msg; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 684 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 685 | } ## end sub _make_default_log_file_handler | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 686 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 687 | =begin comment | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 688 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 689 | Internal Utility function. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 690 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 691 | =end comment | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 692 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 693 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 694 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 695 | 2537 | ▶ | sub _is_empty { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_is_empty: called CC=4 SCAR=19.7
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 696 | 0 | ▶ | my $arg = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_is_empty: not called CC=4 SCAR=19.7
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 697 | 0 | ▶ | return 1 if ( !$arg ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 698 | 0 | ▶ | if ( ref $arg eq 'HASH' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 699 | 0 | ▶ | return 1 unless ( scalar keys %{$arg} ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 700 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 701 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 702 | } ## end sub _is_empty | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 703 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 704 | =begin comment | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 705 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 706 | Add the prefix of time to the passed parameter and return it as a string. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 707 | The caller information is passed to this method as a parameter. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 708 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 709 | =end comment | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 710 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 711 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 712 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 713 | 37 | ▶ | sub _make_log_string { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_make_log_string: called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 714 | 0 | ▶ | my ( $s, $mi, $h, $d, $m, $y ) = ( localtime(time) )[ 0 .. 6 ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_make_log_string: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 715 | 0 | my $date_prefix = sprintf "%04d/%02d/%02d %02d:%02d:%02d", $y + 1900, $m + 1, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 716 | $d, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 717 | $h, $mi, $s; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 718 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 719 | 0 | return '[' . $date_prefix . ']' . join( '', @_, "\n" ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 720 | } ## end sub _make_log_string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 721 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 722 | =pod | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 723 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 724 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 725 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 726 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 727 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||