| 1 | package MojoX::Log::Fast; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 2 | ▶ | use Mojo::Base 'Mojo::Log'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 2 | ▶ | use Carp 'croak'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | |||||||||||||||||||||
| 6 | 2 | our $VERSION = 'v1.2.0'; | |||||||||||||||||||
| 7 | |||||||||||||||||||||
| 8 | 2 | ▶ | use Log::Fast; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | 2 | my %MapLevel = ( | |||||||||||||||||||
| 12 | debug => 'DEBUG', | ||||||||||||||||||||
| 13 | info => 'INFO', | ||||||||||||||||||||
| 14 | warn => 'WARN', | ||||||||||||||||||||
| 15 | error => 'ERR', | ||||||||||||||||||||
| 16 | fatal => 'ERR', | ||||||||||||||||||||
| 17 | ); | ||||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | |||||||||||||||||||||
| 20 | 0 | ▶ | sub new { | ||||||||||||||||||
|
Subroutine
new: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||
| 21 | 0 | my $self = shift->SUPER::new(); | |||||||||||||||||||
| 22 | 0 | ▶ | $self->{'_logger'} = shift || Log::Fast->global(); | ||||||||||||||||||
|
Condition0%0/3
shift() || 'Log::Fast'->global
MC/DC0%0/2
shift() || 'Log::Fast'->global
shift()
'Log::Fast'->global
Truth table0%0/3
A || B
A= shift()B= 'Log::Fast'->global
| |||||||||||||||||||||
| 23 | 0 | ▶ | if ($ENV{MOJO_LOG_LEVEL}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 24 | 0 | $self->level($ENV{MOJO_LOG_LEVEL}); | |||||||||||||||||||
| 25 | } | ||||||||||||||||||||
| 26 | else { | ||||||||||||||||||||
| 27 | 0 | $self->level({reverse %MapLevel}->{ $self->{_logger}->level }); | |||||||||||||||||||
| 28 | } | ||||||||||||||||||||
| 29 | 0 | $self->unsubscribe('message'); | |||||||||||||||||||
| 30 | 0 | $self->on(message => \&_message); | |||||||||||||||||||
| 31 | 0 | return $self; | |||||||||||||||||||
| 32 | } | ||||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | 0 | ▶ | sub context { | ||||||||||||||||||
|
Subroutine
context: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 35 | 0 | my ($parent, @context) = @_; | |||||||||||||||||||
| 36 | 0 | my $self = $parent->new(); | |||||||||||||||||||
| 37 | 0 | $self->level($parent->level); | |||||||||||||||||||
| 38 | 0 | $self->{'context'} = \@context; | |||||||||||||||||||
| 39 | 0 | return $self; | |||||||||||||||||||
| 40 | } | ||||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | 0 | ▶ | sub config { return shift->{'_logger'}->config(@_); } | ||||||||||||||||||
|
Subroutine
config: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 43 | 0 | ▶ | sub ident { return shift->{'_logger'}->ident(@_); } | ||||||||||||||||||
|
Subroutine
ident: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 44 | |||||||||||||||||||||
| 45 | 0 | ▶ | sub handle { croak q{log->handle: not supported, use log->config} }; | ||||||||||||||||||
|
Subroutine
handle: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 46 | 0 | ▶ | sub path { croak q{log->path: not supported, use log->config} }; | ||||||||||||||||||
|
Subroutine
path: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 47 | 0 | ▶ | sub format { croak q{log->format: not implemented} }; ## no critic(ProhibitBuiltinHomonyms) | ||||||||||||||||||
|
Subroutine
format: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 48 | |||||||||||||||||||||
| 49 | 0 | ▶ | sub level { | ||||||||||||||||||
|
Subroutine
level: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||
| 50 | 0 | ▶ | if (@_ == 1) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 51 | 0 | ▶ | return $_[0]{'level'} if exists $_[0]{'level'}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 52 | 0 | return $_[0]{'level'} = 'debug'; | |||||||||||||||||||
| 53 | } | ||||||||||||||||||||
| 54 | 0 | ▶ | $_[0]{'level'} = $ENV{MOJO_LOG_LEVEL} || $_[1]; | ||||||||||||||||||
|
Condition0%0/3
$ENV{'MOJO_LOG_LEVEL'} || $_[1]
MC/DC0%0/2
$ENV{'MOJO_LOG_LEVEL'} || $_[1]
$ENV{'MOJO_LOG_LEVEL'}
$_[1]
Truth table0%0/3
A || B
A= $ENV{'MOJO_LOG_LEVEL'}B= $_[1]
| |||||||||||||||||||||
| 55 | 0 | ▶ | $_[0]{'_logger'}->level($MapLevel{ $ENV{MOJO_LOG_LEVEL} || $_[1] }); | ||||||||||||||||||
|
Condition0%0/3
$ENV{'MOJO_LOG_LEVEL'} || $_[1]
MC/DC0%0/2
$ENV{'MOJO_LOG_LEVEL'} || $_[1]
$ENV{'MOJO_LOG_LEVEL'}
$_[1]
Truth table0%0/3
A || B
A= $ENV{'MOJO_LOG_LEVEL'}B= $_[1]
| |||||||||||||||||||||
| 56 | 0 | return $_[0]; | |||||||||||||||||||
| 57 | } | ||||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | 0 | ▶ | sub _message { | ||||||||||||||||||
|
Subroutine
_message: not called CC=5 SCAR=34.0
| |||||||||||||||||||||
| 60 | 0 | my ($self, $level, @lines) = @_; | |||||||||||||||||||
| 61 | 0 | ▶ | if ($self->{'context'}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 62 | 0 | unshift @lines, @{$self->{context}} | |||||||||||||||||||
| 63 | } | ||||||||||||||||||||
| 64 | 0 | ▶ | if ($level eq 'debug') { | ||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||
| 65 | 0 | $self->{'_logger'}->DEBUG(join q{ }, @lines); | |||||||||||||||||||
| 66 | } elsif ($level eq 'info') { | ||||||||||||||||||||
| 67 | 0 | $self->{'_logger'}->INFO(join q{ }, @lines); | |||||||||||||||||||
| 68 | } elsif ($level eq 'warn') { | ||||||||||||||||||||
| 69 | 0 | $self->{'_logger'}->WARN(join q{ }, @lines); | |||||||||||||||||||
| 70 | } else { # error, fatal | ||||||||||||||||||||
| 71 | 0 | $self->{'_logger'}->ERR(join q{ }, @lines); | |||||||||||||||||||
| 72 | } | ||||||||||||||||||||
| 73 | 0 | return; | |||||||||||||||||||
| 74 | } | ||||||||||||||||||||
| 75 | |||||||||||||||||||||
| 76 | 2 | 1; # Magic true value required at end of module | |||||||||||||||||||
| 77 | __END__ | ||||||||||||||||||||