| 1 | package Amazon::S3::Logger; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 12 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 12 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | 12 | ▶ | use Amazon::S3::Constants qw{ :chars }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 12 | ▶ | use English qw{-no_match_vars}; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 12 | ▶ | use POSIX; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 12 | ▶ | use Readonly; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 12 | ▶ | use Scalar::Util qw{ reftype }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | 12 | our $VERSION = '2.1.4'; ## no critic (RequireInterpolationOfMetachars) | |||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | 12 | Readonly::Hash our %LOG_LEVELS => ( | |||||||||||||||||||||||||||||||||||||||||
| 16 | trace => 5, | ||||||||||||||||||||||||||||||||||||||||||
| 17 | debug => 4, | ||||||||||||||||||||||||||||||||||||||||||
| 18 | info => 3, | ||||||||||||||||||||||||||||||||||||||||||
| 19 | warn => 2, | ||||||||||||||||||||||||||||||||||||||||||
| 20 | error => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 21 | fatal => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 22 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | { | ||||||||||||||||||||||||||||||||||||||||||
| 25 | 12 | ▶ | no strict 'refs'; ## no critic (ProhibitNoStrict) | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | 12 | foreach my $level (qw{fatal error warn info debug trace}) { | |||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | 72 | ▶ | *{ __PACKAGE__ . $DOUBLE_COLON . $level } = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | 174 | my ( $self, @message ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 31 | 174 | $self->_log_message( $level, @message ); | |||||||||||||||||||||||||||||||||||||||||
| 32 | 72 | }; | |||||||||||||||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 37 | 24 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 39 | 24 | my ( $class, @args ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | 24 | ▶ | my $options = ref $args[0] ? $args[0] : {@args}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | 24 | return bless $options, $class; | |||||||||||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||
| 46 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 47 | 23 | ▶ | sub level { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
level: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 49 | 23 | my ( $self, @args ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||
| 51 | 23 | ▶ | if (@args) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | 6 | $self->{log_level} = $args[0]; | |||||||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | 23 | return $self->{log_level}; | |||||||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||
| 58 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 59 | 174 | ▶ | sub _log_message { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_log_message: called CC=6 SCAR=19.3
| |||||||||||||||||||||||||||||||||||||||||||
| 60 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 61 | 174 | my ( $self, $level, @message ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | 174 | ▶ | return if $LOG_LEVELS{ lc $level } > $LOG_LEVELS{ lc $self->{log_level} }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | 36 | ▶ | return if !@message; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||
| 66 | 36 | my $log_message; | |||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | 36 | ▶ | if ( defined $message[0] | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
defined $message[0] and ref $message[0] and builtin::reftype($message[0]) eq "CODE"
defined $message[0] and ref $message[0]
MC/DC0%0/3
defined $message[0] and ref $message[0] and builtin::reftype($message[0]) eq "CODE"
defined $message[0]
ref $message[0]
builtin::reftype($message[0]) eq "CODE"
Truth table25%1/4
A and B and C
A= defined $message[0]B= ref $message[0]C= builtin::reftype($message[0]) eq "CODE"
| |||||||||||||||||||||||||||||||||||||||||||
| 69 | && ref $message[0] | ||||||||||||||||||||||||||||||||||||||||||
| 70 | && reftype( $message[0] ) eq 'CODE' ) { | ||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | $log_message = $message[0]->(); | |||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||
| 73 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 74 | 36 | $log_message = join $EMPTY, @message; | |||||||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||
| 77 | 36 | chomp $log_message; | |||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | 36 | my @tm = localtime time; | |||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||
| 81 | 36 | my $timestamp = POSIX::strftime '%Y/%m/%d %H:%M:%S', @tm; | |||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||
| 83 | 36 | return print {*STDERR} sprintf qq{%s: %s %s %s\n}, uc $level, $timestamp, $PROCESS_ID, $log_message; | |||||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||
| 86 | 12 | 1; | |||||||||||||||||||||||||||||||||||||||||