blib/lib/Dancer2/Logger/Syslog.pm

filter: Statementstmt 92.0% 46 / 50 Branchbran 50.0% 1 / 2 Conditioncond 31.8% 7 / 22 MC/DCmcdc 0.0% 0 / 11 Subroutinesub 100% 7 / 7 Podpod 100% 1 / 1 totaltotal 66.6% 62 / 93 CC 11 SCAR 28.7
CC
11
Cov
73%
_syslog_open
29.1
log
2.0
BEGIN
1.0
CRAP 17.6
↑ Summary
1 package Dancer2::Logger::Syslog;
2 # ABSTRACT: Dancer2 logger engine for Sys::Syslog
3 2 $Dancer2::Logger::Syslog::VERSION = '0.5';
4  
5 4 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use File::Basename 'basename';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 ▶use Sys::Syslog qw(:standard :extended);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 4 ▶use Dancer2::Core::Types;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 2 with 'Dancer2::Core::Role::Logger';
12  
13 2 has 'log_open' => (
14 is => 'ro',
15 isa => Bool,
16 lazy => 1,
17 builder => '_syslog_open',
18 );
19  
20 # Set by calling function
21 2 has facility => (
22 is => 'ro',
23 isa => Str,
24 lazy => 1,
25 );
26  
27 2 has ident => (
28 is => 'ro',
29 isa => Str,
30 lazy => 1,
31 );
32  
33 2 has logopt => (
34 is => 'ro',
35 isa => Str,
36 lazy => 1,
37 );
38  
39 2 has host => (
40 is => 'ro',
41 isa => Str,
42 lazy => 1,
43 );
44  
45 2 has type => (
46 is => 'ro',
47 isa => Str,
48 lazy => 1,
49 );
50  
51 2 has port => (
52 is => 'ro',
53 isa => Str,
54 lazy => 1,
55 );
56  
57  
58 2 ▶sub _syslog_open {
Subroutine _syslog_open: called CC=10 SCAR=33.7
59 2 my $self = shift;
60  
61 2 ▶ my $facility = $self->facility || 'USER';
Condition50%1/2
$self->facility || 'USER'
l!l
02
MC/DC0%0/1
$self->facility || 'USER'
$self->facility
Truth table50%1/2
A
A= $self->facility
Aresult
11
00
62 my $ident = $self->ident
63 || $self->app_name
64 || $ENV{DANCER_APPDIR}
65 2 ▶ || basename($0);
Condition33%3/9
$self->ident || $self->app_name || $ENV{'DANCER_APPDIR'} || basename($0)
l!l&&r!l&&!r
200
$self->ident or $self->app_name or $ENV{"DANCER_APPDIR"}
l!l&&r!l&&!r
200
$self->ident or $self->app_name
l!l&&r!l&&!r
020
MC/DC0%0/4
$self->ident || $self->app_name || $ENV{'DANCER_APPDIR'} || basename($0)
$self->ident $self->app_name $ENV{"DANCER_APPDIR"} basename($0)
Truth table20%1/5
A or B or C || D
A= $self->identB= $self->app_nameC= $ENV{"DANCER_APPDIR"}D= basename($0)
ABCDresult
1XXX1
01XX1
001X1
00011
00000
66 2 ▶ my $logopt = $self->logopt || 'pid';
Condition50%1/2
$self->logopt || 'pid'
l!l
02
MC/DC0%0/1
$self->logopt || 'pid'
$self->logopt
Truth table50%1/2
A
A= $self->logopt
Aresult
11
00
67  
68 2 ▶ if ( $self->host && ( $Sys::Syslog::VERSION >= 0.33 )) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->host and $Sys::Syslog::VERSION >= "0.33") 0 2 2
Condition33%1/3
$self->host and $Sys::Syslog::VERSION >= "0.33"
!ll&&!rl&&r
200
MC/DC0%0/2
$self->host and $Sys::Syslog::VERSION >= "0.33"
$self->host $Sys::Syslog::VERSION >= "0.33"
Truth table33%1/3
A and B
A= $self->hostB= $Sys::Syslog::VERSION >= "0.33"
ABresult
0X0
100
111
69 0 my $host = $self->host;
70 0 ▶ my $type = $self->type || 'udp';
Condition0%0/2
$self->type || 'udp'
l!l
00
MC/DC0%0/1
$self->type || 'udp'
$self->type
Truth table0%0/2
A
A= $self->type
Aresult
11
00
71 0 ▶ my $port = $self->port || 53;
Condition0%0/2
$self->port || 53
l!l
00
MC/DC0%0/1
$self->port || 53
$self->port
Truth table0%0/2
A
A= $self->port
Aresult
11
00
72 0 setlogsock( { host => $host, type => $type, port => $port } )
73 }
74 2 openlog($ident, $logopt, $facility);
75 2 1; # openlog() will have croaked if it can't connect
76 }
77  
78 1 ▶sub DESTROY { closelog() }
Subroutine DESTROY: called CC=1 SCAR=0.0
79  
80 6 ▶sub log {
Subroutine log: called CC=2 SCAR=7.0
Pod documented
81 6 my ($self, $level, $message) = @_;
82  
83 6 $self->log_open;
84  
85 6 my $syslog_levels = {
86 core => 'debug',
87 debug => 'debug',
88 warning => 'warning',
89 error => 'err',
90 info => 'info',
91 };
92  
93 6 ▶ $level = $syslog_levels->{$level} || 'debug';
Condition50%1/2
$syslog_levels->{$level} || 'debug'
l!l
60
MC/DC0%0/1
$syslog_levels->{$level} || 'debug'
$syslog_levels->{$level}
Truth table50%1/2
A
A= $syslog_levels->{$level}
Aresult
11
00
94 6 my $fm = $self->format_message($level => $message);
95 6 syslog($level, $fm);
96 }
97  
98 2 1;
99  
100 __END__
↑ Summary