« blib/lib/SignalWire/Agents/REST/Namespaces/PhoneNumbers.pm
↑ Summary
blib/lib/SignalWire/Agents/Prefabs/Receptionist.pm »
| 1 | package SignalWire::Agents::Logging; | ||||||||||||||||||||
| 2 | 4 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 3 | 4 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 4 | ▶ | use Moo; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | |||||||||||||||||||||
| 6 | # Log levels in ascending severity | ||||||||||||||||||||
| 7 | 4 | my %LEVELS = ( | |||||||||||||||||||
| 8 | debug => 0, | ||||||||||||||||||||
| 9 | info => 1, | ||||||||||||||||||||
| 10 | warn => 2, | ||||||||||||||||||||
| 11 | error => 3, | ||||||||||||||||||||
| 12 | ); | ||||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | has 'name' => ( | ||||||||||||||||||||
| 15 | is => 'ro', | ||||||||||||||||||||
| 16 | 0 | ▶ | default => sub { 'signalwire' }, | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 17 | 4 | ); | |||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | has 'level' => ( | ||||||||||||||||||||
| 20 | is => 'rw', | ||||||||||||||||||||
| 21 | 5 | ▶ | default => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.2
| |||||||||||||||||||||
| 22 | 5 | ▶ | my $env = $ENV{SIGNALWIRE_LOG_LEVEL} // 'info'; | ||||||||||||||||||
|
Condition50%1/2
$ENV{"SIGNALWIRE_LOG_LEVEL"} // "info"
MC/DC0%0/1
$ENV{"SIGNALWIRE_LOG_LEVEL"} // "info"
$ENV{"SIGNALWIRE_LOG_LEVEL"}
Truth table50%1/2
A
A= $ENV{"SIGNALWIRE_LOG_LEVEL"}
| |||||||||||||||||||||
| 23 | 5 | return lc($env); | |||||||||||||||||||
| 24 | }, | ||||||||||||||||||||
| 25 | 4 | ); | |||||||||||||||||||
| 26 | |||||||||||||||||||||
| 27 | has 'suppressed' => ( | ||||||||||||||||||||
| 28 | is => 'rw', | ||||||||||||||||||||
| 29 | 5 | ▶ | default => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=12.0
| |||||||||||||||||||||
| 30 | 5 | ▶ | my $mode = $ENV{SIGNALWIRE_LOG_MODE} // ''; | ||||||||||||||||||
|
Condition50%1/2
$ENV{"SIGNALWIRE_LOG_MODE"} // ""
MC/DC0%0/1
$ENV{"SIGNALWIRE_LOG_MODE"} // ""
$ENV{"SIGNALWIRE_LOG_MODE"}
Truth table50%1/2
A
A= $ENV{"SIGNALWIRE_LOG_MODE"}
| |||||||||||||||||||||
| 31 | 5 | ▶ | return lc($mode) eq 'off' ? 1 : 0; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 32 | }, | ||||||||||||||||||||
| 33 | 4 | ); | |||||||||||||||||||
| 34 | |||||||||||||||||||||
| 35 | 10 | ▶ | sub _should_log { | ||||||||||||||||||
|
Subroutine
_should_log: called CC=4 SCAR=14.1
| |||||||||||||||||||||
| 36 | 10 | my ($self, $msg_level) = @_; | |||||||||||||||||||
| 37 | 10 | ▶ | return 0 if $self->suppressed; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 38 | 9 | ▶ | my $current = $LEVELS{ $self->level } // 1; | ||||||||||||||||||
|
Condition50%1/2
$LEVELS{$self->level} // 1
MC/DC0%0/1
$LEVELS{$self->level} // 1
$LEVELS{$self->level}
Truth table50%1/2
A
A= $LEVELS{$self->level}
| |||||||||||||||||||||
| 39 | 9 | ▶ | my $target = $LEVELS{ $msg_level } // 1; | ||||||||||||||||||
|
Condition50%1/2
$LEVELS{$msg_level} // 1
MC/DC0%0/1
$LEVELS{$msg_level} // 1
$LEVELS{$msg_level}
Truth table50%1/2
A
A= $LEVELS{$msg_level}
| |||||||||||||||||||||
| 40 | 9 | return $target >= $current; | |||||||||||||||||||
| 41 | } | ||||||||||||||||||||
| 42 | |||||||||||||||||||||
| 43 | 4 | ▶ | sub _log { | ||||||||||||||||||
|
Subroutine
_log: called CC=2 SCAR=11.6
| |||||||||||||||||||||
| 44 | 4 | my ($self, $level, @msgs) = @_; | |||||||||||||||||||
| 45 | 4 | ▶ | return unless $self->_should_log($level); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 46 | 0 | my $tag = uc($level); | |||||||||||||||||||
| 47 | 0 | my $name = $self->name; | |||||||||||||||||||
| 48 | 0 | my $msg = join(' ', @msgs); | |||||||||||||||||||
| 49 | 0 | my $ts = _timestamp(); | |||||||||||||||||||
| 50 | 0 | print STDERR "[$ts] [$tag] [$name] $msg\n"; | |||||||||||||||||||
| 51 | } | ||||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | 4 | ▶ | sub debug { shift->_log('debug', @_) } | ||||||||||||||||||
|
Subroutine
debug: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 54 | 0 | ▶ | sub info { shift->_log('info', @_) } | ||||||||||||||||||
|
Subroutine
info: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 55 | 0 | ▶ | sub warn { shift->_log('warn', @_) } | ||||||||||||||||||
|
Subroutine
warn: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 56 | 0 | ▶ | sub error { shift->_log('error', @_) } | ||||||||||||||||||
|
Subroutine
error: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | 0 | ▶ | sub _timestamp { | ||||||||||||||||||
|
Subroutine
_timestamp: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 59 | 0 | my @t = localtime; | |||||||||||||||||||
| 60 | 0 | return sprintf('%04d-%02d-%02d %02d:%02d:%02d', | |||||||||||||||||||
| 61 | $t[5]+1900, $t[4]+1, $t[3], $t[2], $t[1], $t[0]); | ||||||||||||||||||||
| 62 | } | ||||||||||||||||||||
| 63 | |||||||||||||||||||||
| 64 | # Singleton-ish factory | ||||||||||||||||||||
| 65 | 4 | my %loggers; | |||||||||||||||||||
| 66 | |||||||||||||||||||||
| 67 | 9 | ▶ | sub get_logger { | ||||||||||||||||||
|
Subroutine
get_logger: called CC=3 SCAR=11.3
Pod
undocumented
| |||||||||||||||||||||
| 68 | 9 | my ($class, $name) = @_; | |||||||||||||||||||
| 69 | 9 | ▶ | $name //= 'signalwire'; | ||||||||||||||||||
|
Condition50%1/2
$name //= "signalwire"
MC/DC0%0/1
$name //= "signalwire"
$name
Truth table50%1/2
A
A= $name
| |||||||||||||||||||||
| 70 | 9 | ▶ | $loggers{$name} //= SignalWire::Agents::Logging->new(name => $name); | ||||||||||||||||||
|
Condition66%2/3
$loggers{$name} //= "SignalWire::Agents::Logging"->new("name", $name)
MC/DC0%0/2
$loggers{$name} //= "SignalWire::Agents::Logging"->new("name", $name)
$loggers{$name}
"SignalWire::Agents::Logging"->new("name", $name)
Truth table66%2/3
A //= B
A= $loggers{$name}B= "SignalWire::Agents::Logging"->new("name", $name)
| |||||||||||||||||||||
| 71 | 9 | return $loggers{$name}; | |||||||||||||||||||
| 72 | } | ||||||||||||||||||||
| 73 | |||||||||||||||||||||
| 74 | 4 | 1; | |||||||||||||||||||