| 1 | package Clustericious::Log; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 64 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 64 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 64 | ▶ | use List::Util qw( first ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 64 | ▶ | use Log::Log4perl qw( :easy ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 64 | ▶ | use MojoX::Log::Log4perl; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 64 | ▶ | use File::ReadBackwards; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 64 | ▶ | use Clustericious; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | # ABSTRACT: A Log::Log4perl wrapper for use with Clustericious. | ||||||||||||||||||||||||||||||||||||||||||
| 12 | 64 | our $VERSION = '1.29'; # VERSION | |||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | 222 | ▶ | sub import { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
import: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | 222 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||
| 17 | 222 | my $dest = caller; | |||||||||||||||||||||||||||||||||||||||||
| 18 | 222 | my %args = @_; | |||||||||||||||||||||||||||||||||||||||||
| 19 | 222 | ▶ | if (my $app_name = $args{-init_logging}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | 2 | init_logging($app_name); | |||||||||||||||||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||||||||||||||||
| 22 | 222 | @_ = ($class, ':easy'); | |||||||||||||||||||||||||||||||||||||||||
| 23 | 222 | goto \&Log::Log4perl::import; | |||||||||||||||||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | 64 | our $initPid; | |||||||||||||||||||||||||||||||||||||||||
| 28 | 51 | ▶ | sub init_logging { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
init_logging: called CC=11 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | 51 | my $app_name = shift; | |||||||||||||||||||||||||||||||||||||||||
| 30 | 51 | ▶ | $app_name = shift if $app_name eq __PACKAGE__; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | 51 | ▶ | $app_name = $ENV{MOJO_APP} unless $app_name && $app_name ne 'Clustericious::App'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$app_name and $app_name ne "Clustericious::App"
MC/DC0%0/2
$app_name and $app_name ne "Clustericious::App"
$app_name
$app_name ne "Clustericious::App"
Truth table33%1/3
A and B
A= $app_nameB= $app_name ne "Clustericious::App"
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||
| 33 | # Force reinitialization after a fork | ||||||||||||||||||||||||||||||||||||||||||
| 34 | 51 | ▶ | $Log::Log4perl::Logger::INITIALIZED = 0 if $initPid && $initPid != $$; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$Clustericious::Log::initPid and $Clustericious::Log::initPid != $$
MC/DC0%0/2
$Clustericious::Log::initPid and $Clustericious::Log::initPid != $$
$Clustericious::Log::initPid
$Clustericious::Log::initPid != $$
Truth table66%2/3
A and B
A= $Clustericious::Log::initPidB= $Clustericious::Log::initPid != $$
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | 51 | $initPid = $$; | |||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | # Logging | ||||||||||||||||||||||||||||||||||||||||||
| 38 | 51 | ▶ | $ENV{LOG_LEVEL} ||= 'WARN'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$ENV{"LOG_LEVEL"} ||= "WARN"
MC/DC100%1/1
$ENV{"LOG_LEVEL"} ||= "WARN"
$ENV{"LOG_LEVEL"}
Truth table100%2/2
A
A= $ENV{"LOG_LEVEL"}
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | 51 | my $l4p_dir; # dir with log config file. | |||||||||||||||||||||||||||||||||||||||||
| 41 | my $l4p_pat; # pattern for screen logging | ||||||||||||||||||||||||||||||||||||||||||
| 42 | 51 | my $l4p_file; # file (global or app specific) | |||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | 51 | ▶ | $l4p_dir = first { -d $_ && (-e "$_/log4perl.conf" || -e "$_/$app_name.log4perl.conf") } Clustericious->_config_path; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.8
Branch: 1 branch
Condition66%4/6
-d $_ && (-e "$_/log4perl.conf" || -e "$_/$app_name.log4perl.conf")
-e "$_/log4perl.conf" or -e "$_/$app_name.log4perl.conf"
MC/DC33%1/3
-d $_ && (-e "$_/log4perl.conf" || -e "$_/$app_name.log4perl.conf")
-d $_
-e "$_/log4perl.conf"
-e "$_/$app_name.log4perl.conf"
Truth table50%2/4
A && B or C
A= -d $_B= -e "$_/log4perl.conf"C= -e "$_/$app_name.log4perl.conf"
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | 51 | $l4p_pat = "[%d] [%Z %H %P] %5p: %m%n"; | |||||||||||||||||||||||||||||||||||||||||
| 46 | 51 | ▶ | if ($l4p_dir) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | 27 | ▶ | $l4p_file = first {-e "$l4p_dir/$_"} ("$app_name.log4perl.conf", "log4perl.conf"); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | ▶ | Log::Log4perl::Layout::PatternLayout::add_global_cspec('Z', sub {$app_name}); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | my $logger = MojoX::Log::Log4perl->new( $l4p_dir ? "$l4p_dir/$l4p_file": | ||||||||||||||||||||||||||||||||||||||||||
| 53 | { # default config | ||||||||||||||||||||||||||||||||||||||||||
| 54 | ($ENV{LOG_FILE} ? ( | ||||||||||||||||||||||||||||||||||||||||||
| 55 | 51 | ▶ | "log4perl.rootLogger" => "$ENV{LOG_LEVEL}, File1", | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | "log4perl.appender.File1" => "Log::Log4perl::Appender::File", | ||||||||||||||||||||||||||||||||||||||||||
| 57 | "log4perl.appender.File1.layout" => "PatternLayout", | ||||||||||||||||||||||||||||||||||||||||||
| 58 | "log4perl.appender.File1.filename" => "$ENV{LOG_FILE}", | ||||||||||||||||||||||||||||||||||||||||||
| 59 | "log4perl.appender.File1.layout.ConversionPattern" => "[%d] [%Z %H %P] %5p: %m%n", | ||||||||||||||||||||||||||||||||||||||||||
| 60 | ):( | ||||||||||||||||||||||||||||||||||||||||||
| 61 | "log4perl.rootLogger" => "$ENV{LOG_LEVEL}, SCREEN", | ||||||||||||||||||||||||||||||||||||||||||
| 62 | "log4perl.appender.SCREEN" => "Log::Log4perl::Appender::Screen", | ||||||||||||||||||||||||||||||||||||||||||
| 63 | "log4perl.appender.SCREEN.layout" => "PatternLayout", | ||||||||||||||||||||||||||||||||||||||||||
| 64 | "log4perl.appender.SCREEN.layout.ConversionPattern" => "$l4p_pat", | ||||||||||||||||||||||||||||||||||||||||||
| 65 | )), | ||||||||||||||||||||||||||||||||||||||||||
| 66 | # These categories (%c) are too verbose by default : | ||||||||||||||||||||||||||||||||||||||||||
| 67 | "log4perl.logger.Mojolicious" => "WARN", | ||||||||||||||||||||||||||||||||||||||||||
| 68 | "log4perl.logger.Mojolicious.Plugin.RequestTimer" => "WARN", | ||||||||||||||||||||||||||||||||||||||||||
| 69 | "log4perl.logger.MojoX.Dispatcher.Routes" => "WARN", | ||||||||||||||||||||||||||||||||||||||||||
| 70 | }); | ||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | 51 | INFO("Initialized logger"); | |||||||||||||||||||||||||||||||||||||||||
| 73 | 51 | ▶ | INFO("Log config found : $l4p_dir/$l4p_file") if $l4p_dir; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 74 | # warn "# started logging ($l4p_dir/log4perl.conf)\n" if $l4p_dir; | ||||||||||||||||||||||||||||||||||||||||||
| 75 | 51 | return $logger; | |||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | ▶ | sub tail { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
tail: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | my %args = @_; | |||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | ▶ | my $count = $args{lines} || 10; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$args{'lines'} || 10
MC/DC0%0/1
$args{'lines'} || 10
$args{'lines'}
Truth table0%0/2
A
A= $args{'lines'}
| |||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | my %appenders = %{ Log::Log4perl->appenders }; | |||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | my ($first) = sort keys %appenders; | |||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | my $obj = $appenders{$first}->{appender}; | |||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | ▶ | $obj->can("filename") or return "no filename for appender $first"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | my $filename = $obj->filename; | |||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | ▶ | my $fp = File::ReadBackwards->new($filename) or return "Can't read $filename : $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | my @lines; | |||||||||||||||||||||||||||||||||||||||||
| 90 | my $line; | ||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | ▶ | while ( defined( $line = $fp->readline ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | unshift @lines, $line; | |||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | ▶ | last if ( (0 + @lines) >= $count); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 94 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | return join '', @lines; | |||||||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||
| 99 | 64 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||
| 101 | __END__ | ||||||||||||||||||||||||||||||||||||||||||