line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# -*- perl -*- |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# $Id: Log.pm,v 1.3 1999/09/26 14:50:13 joe Exp $ |
4
|
|
|
|
|
|
|
# |
5
|
|
|
|
|
|
|
# Net::Daemon - Base class for implementing TCP/IP daemons |
6
|
|
|
|
|
|
|
# |
7
|
|
|
|
|
|
|
# Copyright (C) 1998, Jochen Wiedmann |
8
|
|
|
|
|
|
|
# Am Eisteich 9 |
9
|
|
|
|
|
|
|
# 72555 Metzingen |
10
|
|
|
|
|
|
|
# Germany |
11
|
|
|
|
|
|
|
# |
12
|
|
|
|
|
|
|
# Phone: +49 7123 14887 |
13
|
|
|
|
|
|
|
# Email: joe@ispsoft.de |
14
|
|
|
|
|
|
|
# |
15
|
|
|
|
|
|
|
# All rights reserved. |
16
|
|
|
|
|
|
|
# |
17
|
|
|
|
|
|
|
# You may distribute this package under the terms of either the GNU |
18
|
|
|
|
|
|
|
# General Public License or the Artistic License, as specified in the |
19
|
|
|
|
|
|
|
# Perl README file. |
20
|
|
|
|
|
|
|
# |
21
|
|
|
|
|
|
|
############################################################################ |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
require 5.004; |
24
|
32
|
|
|
32
|
|
191
|
use strict; |
|
32
|
|
|
|
|
63
|
|
|
32
|
|
|
|
|
34471
|
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
package Net::Daemon::Log; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
$Net::Daemon::Log::VERSION = '0.01'; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
############################################################################ |
33
|
|
|
|
|
|
|
# |
34
|
|
|
|
|
|
|
# Name: Log (Instance method) |
35
|
|
|
|
|
|
|
# |
36
|
|
|
|
|
|
|
# Purpose: Does logging |
37
|
|
|
|
|
|
|
# |
38
|
|
|
|
|
|
|
# Inputs: $self - Server instance |
39
|
|
|
|
|
|
|
# |
40
|
|
|
|
|
|
|
# Result: TRUE, if the client has successfully authorized, FALSE |
41
|
|
|
|
|
|
|
# otherwise. |
42
|
|
|
|
|
|
|
# |
43
|
|
|
|
|
|
|
############################################################################ |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub OpenLog($) { |
47
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
48
|
0
|
0
|
|
|
|
|
return 1 unless ref($self); |
49
|
0
|
0
|
|
|
|
|
return $self->{'logfile'} if defined($self->{'logfile'}); |
50
|
0
|
0
|
|
|
|
|
if ($Config::Config{'archname'} =~ /win32/i) { |
51
|
0
|
|
|
|
|
|
require Win32::EventLog; |
52
|
0
|
0
|
|
|
|
|
$self->{'eventLog'} = Win32::EventLog->new(ref($self), '') |
53
|
|
|
|
|
|
|
or die "Cannot open EventLog:" . &Win32::GetLastError(); |
54
|
0
|
|
|
|
|
|
$self->{'$eventId'} = 0; |
55
|
|
|
|
|
|
|
} else { |
56
|
0
|
|
|
|
|
|
eval { require Sys::Syslog }; |
|
0
|
|
|
|
|
|
|
57
|
0
|
0
|
|
|
|
|
if ($@) { |
58
|
0
|
|
|
|
|
|
die "Cannot open Syslog: $@"; |
59
|
|
|
|
|
|
|
} |
60
|
0
|
0
|
0
|
|
|
|
if ($^O ne 'solaris' && $^O ne 'freebsd' && |
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
61
|
|
|
|
|
|
|
defined(&Sys::Syslog::setlogsock) && |
62
|
0
|
|
|
|
|
|
eval { &Sys::Syslog::_PATH_LOG() }) { |
63
|
0
|
|
|
|
|
|
&Sys::Syslog::setlogsock('unix'); |
64
|
|
|
|
|
|
|
} |
65
|
0
|
|
0
|
|
|
|
&Sys::Syslog::openlog($self->{'logname'} || ref($self), 'pid', |
|
|
|
0
|
|
|
|
|
66
|
|
|
|
|
|
|
$self->{'facility'} || 'daemon'); |
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') {
|
|
|
0
|
|
|
|
|
|
78
|
0
|
0
|
|
|
|
|
if (my $sthread = threads->self()) {
|
79
|
0
|
|
|
|
|
|
$tid = $sthread->tid() . ", ";
|
80
|
|
|
|
|
|
|
}
|
81
|
|
|
|
|
|
|
} elsif ($self->{'mode'} eq 'threads') {
|
82
|
0
|
0
|
|
|
|
|
if (my $sthread = Thread->self()) { |
83
|
0
|
|
|
|
|
|
$tid = $sthread->tid() . ", "; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
}
|
87
|
0
|
0
|
|
|
|
|
if ($logfile) { |
|
|
0
|
|
|
|
|
|
88
|
0
|
|
|
|
|
|
my $logtime = $self->LogTime(); |
89
|
0
|
0
|
|
|
|
|
if (ref($logfile)) { |
90
|
0
|
|
|
|
|
|
$logfile->print(sprintf("$logtime $level, $tid$format\n", @args)); |
91
|
|
|
|
|
|
|
} else { |
92
|
0
|
|
|
|
|
|
printf STDERR ("$logtime $level, $tid$format\n", @args); |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
} elsif (my $eventLog = $self->{'eventLog'}) { |
95
|
0
|
|
|
|
|
|
my($type, $category); |
96
|
0
|
0
|
|
|
|
|
if ($level eq 'debug') { |
|
|
0
|
|
|
|
|
|
97
|
0
|
|
|
|
|
|
$type = Win32::EventLog::EVENTLOG_INFORMATION_TYPE(); |
98
|
0
|
|
|
|
|
|
$category = 10; |
99
|
|
|
|
|
|
|
} elsif ($level eq 'notice') { |
100
|
0
|
|
|
|
|
|
$type = Win32::EventLog::EVENTLOG_INFORMATION_TYPE(); |
101
|
0
|
|
|
|
|
|
$category = 20; |
102
|
|
|
|
|
|
|
} else { |
103
|
0
|
|
|
|
|
|
$type = Win32::EventLog::EVENTLOG_ERROR_TYPE(); |
104
|
0
|
|
|
|
|
|
$category = 50; |
105
|
|
|
|
|
|
|
} |
106
|
0
|
|
|
|
|
|
$eventLog->Report({ |
107
|
|
|
|
|
|
|
'Category' => $category, |
108
|
|
|
|
|
|
|
'EventType' => $type, |
109
|
|
|
|
|
|
|
'EventID' => ++$self->{'eventId'}, |
110
|
|
|
|
|
|
|
'Strings' => sprintf($format, @args), |
111
|
|
|
|
|
|
|
'Data' => $tid |
112
|
|
|
|
|
|
|
}); |
113
|
|
|
|
|
|
|
} else { |
114
|
0
|
|
|
|
|
|
&Sys::Syslog::syslog($level, "$tid$format", @args); |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
sub Debug ($$;@) { |
119
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
120
|
0
|
0
|
0
|
|
|
|
if (!ref($self) || $self->{'debug'}) { |
121
|
0
|
|
|
|
|
|
my $fmt = shift; |
122
|
0
|
|
|
|
|
|
$self->Log('debug', $fmt, @_); |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
sub Error ($$;@) { |
127
|
0
|
|
|
0
|
0
|
|
my $self = shift; my $fmt = shift; |
|
0
|
|
|
|
|
|
|
128
|
0
|
|
|
|
|
|
$self->Log('err', $fmt, @_); |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
sub Fatal ($$;@) { |
132
|
0
|
|
|
0
|
0
|
|
my $self = shift; my $fmt = shift; |
|
0
|
|
|
|
|
|
|
133
|
0
|
|
|
|
|
|
my $msg = sprintf($fmt, @_); |
134
|
0
|
|
|
|
|
|
$self->Log('err', $msg); |
135
|
0
|
|
|
|
|
|
my($package, $filename, $line) = caller(); |
136
|
0
|
|
|
|
|
|
die "$msg at $filename line $line."; |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
0
|
|
|
0
|
0
|
|
sub LogTime { scalar(localtime) } |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
1; |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
__END__ |