| 1 | # mamgal - a program for creating static image galleries | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # Copyright 2007-2009 Marcin Owsiany <marcin@owsiany.pl> | ||||||||||||||||||||||||||||||||||||||||||
| 3 | # See the README file for license information | ||||||||||||||||||||||||||||||||||||||||||
| 4 | # A logging subsystem class | ||||||||||||||||||||||||||||||||||||||||||
| 5 | package App::MaMGal::Logger; | ||||||||||||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use base 'App::MaMGal::Base'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | sub init | ||||||||||||||||||||||||||||||||||||||||||
| 12 | 6 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
init: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 6 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 14 | 6 | ▶ | my $fh = shift or croak "filehandle arg required"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 5 | $self->{fh} = $fh; | |||||||||||||||||||||||||||||||||||||||||
| 16 | } | ||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | sub log_message | ||||||||||||||||||||||||||||||||||||||||||
| 19 | 21 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
log_message: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | 21 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 21 | 21 | my $msg = shift; | |||||||||||||||||||||||||||||||||||||||||
| 22 | 21 | ▶ | my $prefix = shift || ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
shift() || ''
MC/DC100%1/1
shift() || ''
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||
| 23 | 21 | ▶ | $prefix .= ': ' if $prefix; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | 21 | $self->{fh}->printf("%s%s\n", $prefix, $msg); | |||||||||||||||||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | 1 | our $not_available_warned_before = 0; | |||||||||||||||||||||||||||||||||||||||||
| 28 | 1 | our $exe_failure_warned_before = 0; | |||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | sub log_exception | ||||||||||||||||||||||||||||||||||||||||||
| 31 | 11 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
log_exception: called CC=12 SCAR=24.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | 11 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 33 | 11 | my $e = shift; | |||||||||||||||||||||||||||||||||||||||||
| 34 | 11 | my $prefix = shift; | |||||||||||||||||||||||||||||||||||||||||
| 35 | 11 | ▶ | if ($e->isa('App::MaMGal::MplayerWrapper::NotAvailableException')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | # TODO this needs to be made thread-safe | ||||||||||||||||||||||||||||||||||||||||||
| 37 | 2 | ▶ | return if $not_available_warned_before; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | 1 | $not_available_warned_before = 1; | |||||||||||||||||||||||||||||||||||||||||
| 39 | } elsif ($e->isa('App::MaMGal::MplayerWrapper::ExecutionFailureException')) { | ||||||||||||||||||||||||||||||||||||||||||
| 40 | # TODO this needs to be made thread-safe | ||||||||||||||||||||||||||||||||||||||||||
| 41 | 3 | ▶ | goto JUST_LOG if $exe_failure_warned_before or (! $e->stdout and ! $e->stderr); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$App::MaMGal::Logger::exe_failure_warned_before or not $e->stdout || $e->stderr
$e->stdout || $e->stderr
MC/DC66%2/3
$App::MaMGal::Logger::exe_failure_warned_before or not $e->stdout || $e->stderr
$App::MaMGal::Logger::exe_failure_warned_before
$e->stdout
$e->stderr
Truth table75%3/4
A or not(B || C)
A= $App::MaMGal::Logger::exe_failure_warned_beforeB= $e->stdoutC= $e->stderr
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | 1 | $exe_failure_warned_before = 1; | |||||||||||||||||||||||||||||||||||||||||
| 43 | 1 | $self->log_message($e->message, $prefix); | |||||||||||||||||||||||||||||||||||||||||
| 44 | 1 | $self->log_message('--------------------- standard output messages -------------------', $prefix); | |||||||||||||||||||||||||||||||||||||||||
| 45 | 1 | ▶ | $self->log_message($_, $prefix) for $e->stdout ? @{$e->stdout} : (); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | 1 | $self->log_message('--------------------- standard error messages --------------------', $prefix); | |||||||||||||||||||||||||||||||||||||||||
| 47 | 1 | ▶ | $self->log_message($_, $prefix) for $e->stderr ? @{$e->stderr} : (); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | 1 | $self->log_message('------------------------------------------------------------------', $prefix); | |||||||||||||||||||||||||||||||||||||||||
| 49 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||
| 50 | } elsif ($e->isa('App::MaMGal::SystemException')) { | ||||||||||||||||||||||||||||||||||||||||||
| 51 | 2 | $self->log_message($e->interpolated_message); | |||||||||||||||||||||||||||||||||||||||||
| 52 | 2 | return; | |||||||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||||||
| 54 | JUST_LOG: | ||||||||||||||||||||||||||||||||||||||||||
| 55 | 7 | $self->log_message($e->message, $prefix); | |||||||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||
| 58 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||