| 1 | package Bio::WGS2NCBI::Logger; | ||||||||||||
| 2 | 5 | ▶ | use Term::ANSIColor; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 3 | 5 | require Exporter; | |||||||||||
| 4 | 5 | ▶ | use base 'Exporter'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | |||||||||||||
| 6 | 5 | our $Complexity = 0; | |||||||||||
| 7 | 5 | our $Verbosity = 0; | |||||||||||
| 8 | 5 | our @EXPORT = qw(DEBUG INFO WARN ERROR); | |||||||||||
| 9 | 5 | our %COLORS = ( | |||||||||||
| 10 | 'DEBUG' => 'blue', | ||||||||||||
| 11 | 'INFO' => 'green', | ||||||||||||
| 12 | 'WARN' => 'yellow', | ||||||||||||
| 13 | 'ERROR' => 'red', | ||||||||||||
| 14 | ); | ||||||||||||
| 15 | |||||||||||||
| 16 | 6 | ▶ | sub LOG ($$) { | ||||||||||
|
Subroutine
LOG: called CC=4 SCAR=17.3
Pod
undocumented
| |||||||||||||
| 17 | 6 | my ($msg,$method) = @_; | |||||||||||
| 18 | |||||||||||||
| 19 | # compose the message. Complex messages do some amount of introspection | ||||||||||||
| 20 | # to figure out where the message originated. | ||||||||||||
| 21 | 6 | my $log; | |||||||||||
| 22 | 6 | ▶ | if ( $Complexity ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 23 | 0 | my ( $package, $file1up, $line1up, $sub ) = caller( 2 ); | |||||||||||
| 24 | 0 | my ( $pack0up, $file, $line, $sub0up ) = caller( 1 ); | |||||||||||
| 25 | 0 | ▶ | $log = sprintf( "%s %s [%s %s] - %s\n", uc $method, $sub || '', $file, $line, $msg ); | ||||||||||
|
Condition0%0/2
$sub || ''
MC/DC0%0/1
$sub || ''
$sub
Truth table0%0/2
A
A= $sub
| |||||||||||||
| 26 | } | ||||||||||||
| 27 | else { | ||||||||||||
| 28 | 6 | $log = $method . ' ' . $msg . "\n"; | |||||||||||
| 29 | } | ||||||||||||
| 30 | |||||||||||||
| 31 | # check if we are actually writing to the terminal rather than a file | ||||||||||||
| 32 | 6 | ▶ | if ( -t STDERR ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 33 | 0 | print STDERR colored( $log, $COLORS{$method} ); | |||||||||||
| 34 | } | ||||||||||||
| 35 | else { | ||||||||||||
| 36 | 6 | print STDERR $log; | |||||||||||
| 37 | } | ||||||||||||
| 38 | 6 | return $Verbosity; | |||||||||||
| 39 | } | ||||||||||||
| 40 | 4 | ▶ | sub DEBUG ($) { LOG shift, 'DEBUG' if $Verbosity >= 3 } | ||||||||||
|
Subroutine
DEBUG: called CC=2 SCAR=7.6
Pod
undocumented
Branch: 1 branch
| |||||||||||||
| 41 | 1 | ▶ | sub INFO ($) { LOG shift, 'INFO' if $Verbosity >= 2 } | ||||||||||
|
Subroutine
INFO: called CC=2 SCAR=7.6
Pod
undocumented
Branch: 1 branch
| |||||||||||||
| 42 | 5 | ▶ | sub WARN ($) { LOG shift, 'WARN' if $Verbosity >= 1 } | ||||||||||
|
Subroutine
WARN: called CC=2 SCAR=7.6
Pod
undocumented
Branch: 1 branch
| |||||||||||||
| 43 | 6 | ▶ | sub ERROR ($) { LOG shift, 'ERROR' if $Verbosity >= 0 } | ||||||||||
|
Subroutine
ERROR: called CC=2 SCAR=7.6
Pod
undocumented
Branch: 1 branch
| |||||||||||||
| 44 | |||||||||||||
| 45 | 5 | 1; | |||||||||||