Daemon/Log.pm

filter: Statementstmt 53.9% 34 / 63 Branchbran 40.0% 12 / 30 Conditioncond 40.0% 8 / 20 MC/DCmcdc 8.3% 1 / 12 Subroutinesub 66.6% 6 / 9 Podpod 0.0% 0 / 6 totaltotal 43.5% 61 / 140 CC 23 SCAR 32.9
CC
23
Cov
48%
Log
53.3
OpenLog
21.0
Debug
3.0
CRAP 27.0
« Daemon/Test.pm ↑ Summary
1 ############################################################################
2 #
3 # Net::Daemon::Log
4 #
5 # Copyright (C) 1998, Jochen Wiedmann
6 # Am Eisteich 9
7 # 72555 Metzingen
8 # Germany
9 #
10 # Phone: +49 7123 14887
11 # Email: joe@ispsoft.de
12 #
13 # All rights reserved.
14 #
15 # You may distribute this package under the terms of either the GNU
16 # General Public License or the Artistic License, as specified in the
17 # Perl README file.
18 #
19 ############################################################################
20  
21 47 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 47 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 package Net::Daemon::Log;
25  
26 47 our $VERSION = '0.49';
27  
28 47 ▶use Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30 ############################################################################
31 #
32 # Name: Log (Instance method)
33 #
34 # Purpose: Does logging
35 #
36 # Inputs: $self - Server instance
37 #
38 # Result: TRUE, if the client has successfully authorized, FALSE
39 # otherwise.
40 #
41 ############################################################################
42  
43 sub OpenLog($) {
44 32 ▶ my $self = shift;
Subroutine OpenLog: called CC=11 SCAR=30.5
Pod undocumented
45 32 ▶ return 1 unless ref($self);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 0 32 32
46 32 ▶ return $self->{'logfile'} if defined( $self->{'logfile'} );
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"logfile"} 18 14 32
47 14 ▶ if ( $Config::Config{'archname'} =~ /win32/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Config::Config{'archname'} =~ /win32/i) { } 0 14 14
48 0 require Win32::EventLog;
49 0 ▶ $self->{'eventLog'} = Win32::EventLog->new( ref($self), '' )
Branch: 1 branch
BranchTrueFalseTotal
$self->{"eventLog"} = "Win32::EventLog"->new(ref $self, "") or die 'Cannot open EventLog:' . Win32::GetLastError() 0 0 0
50 or die "Cannot open EventLog:" . Win32::GetLastError();
51 0 $self->{'$eventId'} = 0;
52 }
53 else {
54 14 eval { require Sys::Syslog };
55 14 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 14 14
56 0 die "Cannot open Syslog: $@";
57 }
58 14 ▶ if ( $^O ne 'solaris'
Branch: 1 branch
BranchTrueFalseTotal
if ($^O ne "solaris" and $^O ne "freebsd" and eval { do { Sys::Syslog::_PATH_LOG() } }) 14 0 14
Condition33%2/6
$^O ne "solaris" and $^O ne "freebsd" and eval { do { Sys::Syslog::_PATH_LOG() } }
!ll&&!rl&&r
0014
$^O ne "solaris" and $^O ne "freebsd"
!ll&&!rl&&r
0014
MC/DC0%0/3
$^O ne "solaris" and $^O ne "freebsd" and eval { do { Sys::Syslog::_PATH_LOG() } }
$^O ne "solaris" $^O ne "freebsd" eval { do { Sys::Syslog::_PATH_LOG() } }
Truth table25%1/4
A and B and C
A= $^O ne "solaris"B= $^O ne "freebsd"C= eval { do { Sys::Syslog::_PATH_LOG() } }
ABCresult
0XX0
10X0
1100
1111
59 && $^O ne 'freebsd'
60 14 && eval { Sys::Syslog::_PATH_LOG() } ) {
61 14 Sys::Syslog::setlogsock('unix');
62 }
63 Sys::Syslog::openlog(
64 $self->{'logname'} || ref($self), 'pid',
65 14 ▶ $self->{'facility'} || 'daemon'
Condition40%2/5
$self->{'logname'} || ref $self
l!l&&r!l&&!r
0140
$self->{'facility'} || 'daemon'
l!l
014
MC/DC0%0/2
$self->{'logname'} || ref $self
$self->{'logname'} ref $self
MC/DC0%0/1
$self->{'facility'} || 'daemon'
$self->{'facility'}
Truth table33%1/3
A || B
A= $self->{'logname'}B= ref $self
ABresult
1X1
011
000
Truth table50%1/2
A
A= $self->{'facility'}
Aresult
11
00
66 );
67 }
68 14 $self->{'logfile'} = 0;
69 }
70  
71 sub Log ($$$;@) {
72 32 ▶ my ( $self, $level, $format, @args ) = @_;
Subroutine Log: called CC=11 SCAR=39.8
Pod undocumented
73 32 ▶ my $logfile = !ref($self) || $self->OpenLog();
Condition33%1/3
!ref($self) || $self->OpenLog
l!l&&r!l&&!r
0032
MC/DC0%0/2
!ref($self) || $self->OpenLog
!ref($self) $self->OpenLog
Truth table33%1/3
not(A) || B
A= !ref($self)B= $self->OpenLog
ABresult
1X1
011
000
74  
75 32 my $tid = '';
76 32 ▶ if ( ref($self) && $self->{'mode'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self and $self->{"mode"}) 32 0 32
Condition33%1/3
ref $self and $self->{"mode"}
!ll&&!rl&&r
0032
MC/DC0%0/2
ref $self and $self->{"mode"}
ref $self $self->{"mode"}
Truth table33%1/3
A and B
A= ref $selfB= $self->{"mode"}
ABresult
0X0
100
111
77 32 ▶ if ( $self->{'mode'} eq 'ithreads' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"mode"} eq "ithreads") 0 32 32
78 0 ▶ if ( my $sthread = threads->self() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $sthread = "threads"->self) 0 0 0
79 0 $tid = $sthread->tid() . ", ";
80 }
81 }
82 }
83 32 ▶ if ($logfile) {
Branch: 2 branches
BranchTrueFalseTotal
if ($logfile) { } 0 32 32
elsif (my $eventLog = $self->{'eventLog'}) { } 0 32 32
84 0 my $logtime = $self->LogTime();
85 0 ▶ if ( ref($logfile) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $logfile) { } 0 0 0
86 0 $logfile->print( sprintf( "$logtime $level, $tid$format\n", @args ) );
87 }
88 else {
89 0 printf STDERR ( "$logtime $level, $tid$format\n", @args );
90 }
91 }
92 elsif ( my $eventLog = $self->{'eventLog'} ) {
93 0 my ( $type, $category );
94 0 ▶ if ( $level eq 'debug' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($level eq 'debug') { } 0 0 0
elsif ($level eq 'notice') { } 0 0 0
95 0 $type = Win32::EventLog::EVENTLOG_INFORMATION_TYPE();
96 0 $category = 10;
97 }
98 elsif ( $level eq 'notice' ) {
99 0 $type = Win32::EventLog::EVENTLOG_INFORMATION_TYPE();
100 0 $category = 20;
101 }
102 else {
103 0 $type = Win32::EventLog::EVENTLOG_ERROR_TYPE();
104 0 $category = 50;
105 }
106 $eventLog->Report(
107 {
108 'Category' => $category,
109 'EventType' => $type,
110 0 'EventID' => ++$self->{'eventId'},
111 'Strings' => sprintf( $format, @args ),
112 'Data' => $tid
113 }
114 );
115 }
116 else {
117 32 Sys::Syslog::syslog( $level, "$tid$format", @args );
118 }
119 }
120  
121 sub Debug ($$;@) {
122 148 ▶ my $self = shift;
Subroutine Debug: called CC=3 SCAR=11.0
Pod undocumented
123 148 ▶ if ( !ref($self) || $self->{'debug'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $self or $self->{"debug"}) 18 130 148
Condition66%2/3
not ref $self or $self->{"debug"}
l!l&&r!l&&!r
018130
MC/DC50%1/2
not ref $self or $self->{"debug"}
not ref $self $self->{"debug"}
Truth table66%2/3
not(A) or B
A= not ref $selfB= $self->{"debug"}
ABresult
1X1
011
000
124 18 my $fmt = shift;
125 18 $self->Log( 'debug', $fmt, @_ );
126 }
127 }
128  
129 sub Error ($$;@) {
130 0 ▶ my $self = shift;
Subroutine Error: not called CC=1 SCAR=6.9
Pod undocumented
131 0 my $fmt = shift;
132 0 $self->Log( 'err', $fmt, @_ );
133 }
134  
135 sub Fatal ($$;@) {
136 0 ▶ my $self = shift;
Subroutine Fatal: not called CC=1 SCAR=6.9
Pod undocumented
137 0 my $fmt = shift;
138 0 my $msg = sprintf( $fmt, @_ );
139 0 $self->Log( 'err', $msg );
140 0 my ( $package, $filename, $line ) = caller();
141 0 die "$msg at $filename line $line.";
142 }
143  
144 0 ▶sub LogTime { scalar(localtime) }
Subroutine LogTime: not called CC=1 SCAR=6.9
Pod undocumented
145  
146 47 1;
147  
148 __END__
« Daemon/Test.pm ↑ Summary