/usr/share/perl5/Net/Daemon/Log.pm is in libnet-daemon-perl 0.48-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 | # -*- perl -*-
#
# $Id: Log.pm,v 1.3 1999/09/26 14:50:13 joe Exp $
#
# Net::Daemon - Base class for implementing TCP/IP daemons
#
# Copyright (C) 1998, Jochen Wiedmann
# Am Eisteich 9
# 72555 Metzingen
# Germany
#
# Phone: +49 7123 14887
# Email: joe@ispsoft.de
#
# All rights reserved.
#
# You may distribute this package under the terms of either the GNU
# General Public License or the Artistic License, as specified in the
# Perl README file.
#
############################################################################
require 5.004;
use strict;
package Net::Daemon::Log;
$Net::Daemon::Log::VERSION = '0.01';
############################################################################
#
# Name: Log (Instance method)
#
# Purpose: Does logging
#
# Inputs: $self - Server instance
#
# Result: TRUE, if the client has successfully authorized, FALSE
# otherwise.
#
############################################################################
sub OpenLog($) {
my $self = shift;
return 1 unless ref($self);
return $self->{'logfile'} if defined($self->{'logfile'});
if ($Config::Config{'archname'} =~ /win32/i) {
require Win32::EventLog;
$self->{'eventLog'} = Win32::EventLog->new(ref($self), '')
or die "Cannot open EventLog:" . &Win32::GetLastError();
$self->{'$eventId'} = 0;
} else {
eval { require Sys::Syslog };
if ($@) {
die "Cannot open Syslog: $@";
}
if ($^O ne 'solaris' && $^O ne 'freebsd' &&
defined(&Sys::Syslog::setlogsock) &&
eval { &Sys::Syslog::_PATH_LOG() }) {
&Sys::Syslog::setlogsock('unix');
}
&Sys::Syslog::openlog($self->{'logname'} || ref($self), 'pid',
$self->{'facility'} || 'daemon');
}
$self->{'logfile'} = 0;
}
sub Log ($$$;@) {
my($self, $level, $format, @args) = @_;
my $logfile = !ref($self) || $self->OpenLog();
my $tid = '';
if (ref($self) && $self->{'mode'}) {
if ($self->{'mode'} eq 'ithreads') {
if (my $sthread = threads->self()) {
$tid = $sthread->tid() . ", ";
}
} elsif ($self->{'mode'} eq 'threads') {
if (my $sthread = Thread->self()) {
$tid = $sthread->tid() . ", ";
}
}
}
if ($logfile) {
my $logtime = $self->LogTime();
if (ref($logfile)) {
$logfile->print(sprintf("$logtime $level, $tid$format\n", @args));
} else {
printf STDERR ("$logtime $level, $tid$format\n", @args);
}
} elsif (my $eventLog = $self->{'eventLog'}) {
my($type, $category);
if ($level eq 'debug') {
$type = Win32::EventLog::EVENTLOG_INFORMATION_TYPE();
$category = 10;
} elsif ($level eq 'notice') {
$type = Win32::EventLog::EVENTLOG_INFORMATION_TYPE();
$category = 20;
} else {
$type = Win32::EventLog::EVENTLOG_ERROR_TYPE();
$category = 50;
}
$eventLog->Report({
'Category' => $category,
'EventType' => $type,
'EventID' => ++$self->{'eventId'},
'Strings' => sprintf($format, @args),
'Data' => $tid
});
} else {
&Sys::Syslog::syslog($level, "$tid$format", @args);
}
}
sub Debug ($$;@) {
my $self = shift;
if (!ref($self) || $self->{'debug'}) {
my $fmt = shift;
$self->Log('debug', $fmt, @_);
}
}
sub Error ($$;@) {
my $self = shift; my $fmt = shift;
$self->Log('err', $fmt, @_);
}
sub Fatal ($$;@) {
my $self = shift; my $fmt = shift;
my $msg = sprintf($fmt, @_);
$self->Log('err', $msg);
my($package, $filename, $line) = caller();
die "$msg at $filename line $line.";
}
sub LogTime { scalar(localtime) }
1;
__END__
=head1 NAME
Net::Daemon::Log - Utility functions for logging
=head1 SYNOPSIS
# Choose logging method: syslog or Win32::EventLog
$self->{'facility'} = 'mail'; # Default: Daemon
$self->{'logfile'} = undef; # Default
# Choose logging method: stderr
$self->{'logfile'} = 1;
# Choose logging method: IO handle
my $file = IO::File->new("my.log", "a");
$self->{'logfile'} = $file;
# Debugging messages (equivalent):
$self->Log('debug', "This is a debugging message");
$self->Debug("This is a debugging message");
# Error messages (equivalent):
$self->Log('err', "This is an error message");
$self->Error("This is an error message");
# Fatal error messages (implies 'die')
$self->Fatal("This is a fatal error message");
=head1 WARNING
THIS IS ALPHA SOFTWARE. It is *only* 'Alpha' because the interface (API)
is not finalised. The Alpha status does not reflect code quality or
stability.
=head1 DESCRIPTION
Net::Daemon::Log is a utility class for portable logging messages.
By default it uses syslog (Unix) or Win32::EventLog (Windows), but
logging messages can also be redirected to stderr or a log file.
=head2 Generic Logging
$self->Log($level, $msg, @args);
This is the generic interface. The logging level is in syslog style,
thus one of the words 'debug', 'info', 'notice', 'err' or 'crit'.
You'll rarely need info and notice and I can hardly imagine a reason
for crit (critical). In 95% of all cases debug and err will be
sufficient.
The logging string $msg is a format string similar to printf.
=head2 Utility methods
$self->Debug($msg, @args);
$self->Error($msg, @args);
$self->Fatal($msg, @args);
These are replacements for logging with levels debug and err. The difference
between the latter two is that Fatal includes throwing a Perl exception.
=head2 Chossing a logging target
By default logging will happen to syslog (Unix) or EventLog (Windows).
However you may choose logging to stderr by setting
$self->{'logfile'} = 1;
This is required if neither of syslog and EventLog is available. An
alternative option is setting
$self->{'logfile'} = $handle;
where $handle is any object supporting a I<print> method, for example
an IO::Handle object. Usually the logging target is choosen as soon
as you call $self->Log() the first time. However, you may force
choosing the target by doing a
$self->OpenLog();
before calling Log the first time.
=head1 MULTITHREADING
The Multithreading capabitities of this class are depending heavily
on the underlying classes Sys::Syslog, Win32::EventLog or IO::Handle.
If they are thread safe, you can well assume that this package is
too. (The exception being that you should better call
$self->OpenLog() before threading.)
=head1 AUTHOR AND COPYRIGHT
Net::Daemon is Copyright (C) 1998, Jochen Wiedmann
Am Eisteich 9
72555 Metzingen
Germany
Phone: +49 7123 14887
Email: joe@ispsoft.de
All rights reserved.
You may distribute this package under the terms of either the GNU
General Public License or the Artistic License, as specified in the
Perl README file.
=head1 SEE ALSO
L<Net::Daemon(3)>, L<Sys::Syslog(3)>, L<Win32::EventLog(3)>,
L<IO::Handle(3)>
=cut
|