line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
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
|
33
|
|
|
33
|
|
213
|
use strict; |
|
33
|
|
|
|
|
64
|
|
|
33
|
|
|
|
|
961
|
|
22
|
33
|
|
|
33
|
|
153
|
use warnings; |
|
33
|
|
|
|
|
62
|
|
|
33
|
|
|
|
|
1485
|
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
package Net::Daemon::Log; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
our $VERSION = '0.49'; |
27
|
|
|
|
|
|
|
|
28
|
33
|
|
|
33
|
|
166
|
use Config; |
|
33
|
|
|
|
|
50
|
|
|
33
|
|
|
|
|
24065
|
|
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
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
45
|
0
|
0
|
|
|
|
|
return 1 unless ref($self); |
46
|
0
|
0
|
|
|
|
|
return $self->{'logfile'} if defined( $self->{'logfile'} ); |
47
|
0
|
0
|
|
|
|
|
if ( $Config::Config{'archname'} =~ /win32/i ) { |
48
|
0
|
|
|
|
|
|
require Win32::EventLog; |
49
|
0
|
0
|
|
|
|
|
$self->{'eventLog'} = Win32::EventLog->new( ref($self), '' ) |
50
|
|
|
|
|
|
|
or die "Cannot open EventLog:" . Win32::GetLastError(); |
51
|
0
|
|
|
|
|
|
$self->{'$eventId'} = 0; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
else { |
54
|
0
|
|
|
|
|
|
eval { require Sys::Syslog }; |
|
0
|
|
|
|
|
|
|
55
|
0
|
0
|
|
|
|
|
if ($@) { |
56
|
0
|
|
|
|
|
|
die "Cannot open Syslog: $@"; |
57
|
|
|
|
|
|
|
} |
58
|
0
|
0
|
0
|
|
|
|
if ( $^O ne 'solaris' |
|
|
|
0
|
|
|
|
|
59
|
|
|
|
|
|
|
&& $^O ne 'freebsd' |
60
|
0
|
|
|
|
|
|
&& eval { Sys::Syslog::_PATH_LOG() } ) { |
61
|
0
|
|
|
|
|
|
Sys::Syslog::setlogsock('unix'); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
Sys::Syslog::openlog( |
64
|
|
|
|
|
|
|
$self->{'logname'} || ref($self), 'pid', |
65
|
0
|
|
0
|
|
|
|
$self->{'facility'} || 'daemon' |
|
|
|
0
|
|
|
|
|
66
|
|
|
|
|
|
|
); |
67
|
|
|
|
|
|
|
} |
68
|
0
|
|
|
|
|
|
$self->{'logfile'} = 0; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub Log ($$$;@) { |
72
|
0
|
|
|
0
|
0
|
|
my ( $self, $level, $format, @args ) = @_; |
73
|
0
|
|
0
|
|
|
|
my $logfile = !ref($self) || $self->OpenLog(); |
74
|
|
|
|
|
|
|
|
75
|
0
|
|
|
|
|
|
my $tid = ''; |
76
|
0
|
0
|
0
|
|
|
|
if ( ref($self) && $self->{'mode'} ) { |
77
|
0
|
0
|
|
|
|
|
if ( $self->{'mode'} eq 'ithreads' ) { |
78
|
0
|
0
|
|
|
|
|
if ( my $sthread = threads->self() ) { |
79
|
0
|
|
|
|
|
|
$tid = $sthread->tid() . ", "; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
} |
83
|
0
|
0
|
|
|
|
|
if ($logfile) { |
|
|
0
|
|
|
|
|
|
84
|
0
|
|
|
|
|
|
my $logtime = $self->LogTime(); |
85
|
0
|
0
|
|
|
|
|
if ( ref($logfile) ) { |
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
|
0
|
|
|
|
|
if ( $level eq 'debug' ) { |
|
|
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
|
0
|
|
|
|
|
|
Sys::Syslog::syslog( $level, "$tid$format", @args ); |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub Debug ($$;@) { |
122
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
123
|
0
|
0
|
0
|
|
|
|
if ( !ref($self) || $self->{'debug'} ) { |
124
|
0
|
|
|
|
|
|
my $fmt = shift; |
125
|
0
|
|
|
|
|
|
$self->Log( 'debug', $fmt, @_ ); |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
sub Error ($$;@) { |
130
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
131
|
0
|
|
|
|
|
|
my $fmt = shift; |
132
|
0
|
|
|
|
|
|
$self->Log( 'err', $fmt, @_ ); |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
sub Fatal ($$;@) { |
136
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
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
|
|
|
0
|
0
|
|
sub LogTime { scalar(localtime) } |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
1; |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
__END__ |