| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | 32 | ▶ | return $self->{'logfile'} if defined( $self->{'logfile'} ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | 14 | ▶ | if ( $Config::Config{'archname'} =~ /win32/i ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | require Win32::EventLog; | |||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | ▶ | $self->{'eventLog'} = Win32::EventLog->new( ref($self), '' ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | die "Cannot open Syslog: $@"; | |||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||
| 58 | 14 | ▶ | if ( $^O ne 'solaris' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$^O ne "solaris" and $^O ne "freebsd" and eval {
do {
Sys::Syslog::_PATH_LOG()
}
}
$^O ne "solaris" and $^O ne "freebsd"
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()
}
}
| |||||||||||||||||||||||||||||||||||||||||||
| 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
$self->{'facility'} || 'daemon'
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
Truth table50%1/2
A
A= $self->{'facility'}
| |||||||||||||||||||||||||||||||||||||||||||
| 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
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
| |||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | 32 | my $tid = ''; | |||||||||||||||||||||||||||||||||||||||||
| 76 | 32 | ▶ | if ( ref($self) && $self->{'mode'} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $self and $self->{"mode"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | 32 | ▶ | if ( $self->{'mode'} eq 'ithreads' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | ▶ | if ( my $sthread = threads->self() ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | $tid = $sthread->tid() . ", "; | |||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||
| 83 | 32 | ▶ | if ($logfile) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | my $logtime = $self->LogTime(); | |||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | ▶ | if ( ref($logfile) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
not ref $self or $self->{"debug"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||||||||||||||||