| 1 | # | ||||||||||||
| 2 | # This file is part of App-Magpie | ||||||||||||
| 3 | # | ||||||||||||
| 4 | # This software is copyright (c) 2011 by Jerome Quelin. | ||||||||||||
| 5 | # | ||||||||||||
| 6 | # This is free software; you can redistribute it and/or modify it under | ||||||||||||
| 7 | # the same terms as the Perl 5 programming language system itself. | ||||||||||||
| 8 | # | ||||||||||||
| 9 | 19 | ▶ | use 5.012; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 10 | 19 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 11 | 19 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 12 | |||||||||||||
| 13 | package App::Magpie::Logger; | ||||||||||||
| 14 | # ABSTRACT: magpie logging facility | ||||||||||||
| 15 | 19 | $App::Magpie::Logger::VERSION = '2.010'; | |||||||||||
| 16 | 19 | ▶ | use DateTime; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 17 | 19 | ▶ | use MooseX::Singleton; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 18 | 19 | ▶ | use MooseX::Has::Sugar; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 19 | 19 | ▶ | use MooseX::SemiAffordanceAccessor; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 20 | 19 | ▶ | use Term::ANSIColor qw{ :constants }; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 21 | |||||||||||||
| 22 | 19 | ▶ | use App::Magpie::Config; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 23 | |||||||||||||
| 24 | |||||||||||||
| 25 | # -- public attributes | ||||||||||||
| 26 | |||||||||||||
| 27 | |||||||||||||
| 28 | 19 | has log_level => ( | |||||||||||
| 29 | ro, lazy_build, | ||||||||||||
| 30 | isa => "Int", | ||||||||||||
| 31 | traits => ['Counter'], | ||||||||||||
| 32 | handles => { | ||||||||||||
| 33 | more_verbose => 'inc', | ||||||||||||
| 34 | less_verbose => 'dec', | ||||||||||||
| 35 | }, | ||||||||||||
| 36 | ); | ||||||||||||
| 37 | |||||||||||||
| 38 | 0 | ▶ | sub _build_log_level { | ||||||||||
|
Subroutine
_build_log_level: not called CC=2 SCAR=17.9
| |||||||||||||
| 39 | 0 | my $config = App::Magpie::Config->instance; | |||||||||||
| 40 | 0 | ▶ | return $config->get( "log", "level" ) // 1; | ||||||||||
|
Condition0%0/2
$config->get("log", "level") // 1
MC/DC0%0/1
$config->get("log", "level") // 1
$config->get("log", "level")
Truth table0%0/2
A
A= $config->get("log", "level")
| |||||||||||||
| 41 | } | ||||||||||||
| 42 | |||||||||||||
| 43 | |||||||||||||
| 44 | # -- public methods | ||||||||||||
| 45 | |||||||||||||
| 46 | |||||||||||||
| 47 | 0 | ▶ | sub log { | ||||||||||
|
Subroutine
log: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||
| 48 | 0 | my $self = shift; | |||||||||||
| 49 | 0 | ▶ | return if $self->log_level < 1; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 50 | 0 | print STDERR YELLOW; | |||||||||||
| 51 | 0 | $self->_log(@_); | |||||||||||
| 52 | 0 | print STDERR RESET; | |||||||||||
| 53 | } | ||||||||||||
| 54 | |||||||||||||
| 55 | 0 | ▶ | sub log_debug { | ||||||||||
|
Subroutine
log_debug: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||
| 56 | 0 | my $self = shift; | |||||||||||
| 57 | 0 | ▶ | return if $self->log_level < 2; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 58 | 0 | print STDERR BLUE; | |||||||||||
| 59 | 0 | $self->_log(@_); | |||||||||||
| 60 | 0 | print STDERR RESET; | |||||||||||
| 61 | } | ||||||||||||
| 62 | |||||||||||||
| 63 | 0 | ▶ | sub log_fatal { | ||||||||||
|
Subroutine
log_fatal: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 64 | 0 | my $self = shift; | |||||||||||
| 65 | 0 | local $Term::ANSIColor::AUTORESET = 1; | |||||||||||
| 66 | 0 | print STDERR BOLD RED; | |||||||||||
| 67 | 0 | $self->_log(@_); | |||||||||||
| 68 | 0 | print STDERR RESET; | |||||||||||
| 69 | 0 | die @_; | |||||||||||
| 70 | } | ||||||||||||
| 71 | |||||||||||||
| 72 | |||||||||||||
| 73 | # -- private methods | ||||||||||||
| 74 | |||||||||||||
| 75 | 0 | ▶ | sub _log { | ||||||||||
|
Subroutine
_log: not called CC=1 SCAR=6.9
| |||||||||||||
| 76 | 0 | my $self = shift; | |||||||||||
| 77 | 0 | my $timestamp = DateTime->now(time_zone=>"local")->hms; | |||||||||||
| 78 | 0 | print STDERR "$timestamp [$$] [magpie] @_\n"; | |||||||||||
| 79 | } | ||||||||||||
| 80 | |||||||||||||
| 81 | |||||||||||||
| 82 | 19 | 1; | |||||||||||
| 83 | |||||||||||||
| 84 | __END__ | ||||||||||||