/usr/share/perl5/Paranoid/Log/Syslog.pm is in libparanoid-perl 0.36-2.
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 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 | # Paranoid::Log::Syslog -- Log Facility Syslog for paranoid programs
#
# (c) 2005, Arthur Corliss <corliss@digitalmages.com>
#
# $Id: Syslog.pm,v 0.83 2010/06/03 19:04:07 acorliss Exp $
#
# This software is licensed under the same terms as Perl, itself.
# Please see http://dev.perl.org/licenses/ for more information.
#
#####################################################################
#####################################################################
#
# Environment definitions
#
#####################################################################
package Paranoid::Log::Syslog;
use 5.006;
use strict;
use warnings;
use vars qw($VERSION);
use Paranoid::Debug qw(:all);
use Unix::Syslog qw(:macros :subs);
use Carp;
($VERSION) = ( q$Revision: 0.83 $ =~ /(\d+(?:\.(\d+))+)/sm );
#####################################################################
#
# Module code follows
#
#####################################################################
sub _setIdent (;$) {
# Purpose: Returns a name for use as the ident field. If you don't want
# the process command as that you can pass an optional name to
# use instead.
# Returns: String
# Usage: $ident = _setIdent();
# Usage: $ident = _setIdent($name);
my $name = shift;
# Use $0 by default
$name = $0 unless defined $name;
# Strip path
$name =~ s#^.*/##sm;
return $name;
}
sub init (;@) {
# Purpose: Exists purely for compliance.
# Returns: True (1)
# Usage: init();
return 1;
}
sub _transFacility ($) {
# Purpose: Translates the string log facilities into the syslog constants
# Returns: Constant scalar value
# Usage: $facility = _transFacility($facilityName);
my $f = lc shift;
my %trans = (
authpriv => LOG_AUTHPRIV,
auth => LOG_AUTHPRIV,
cron => LOG_CRON,
daemon => LOG_DAEMON,
ftp => LOG_FTP,
kern => LOG_KERN,
local0 => LOG_LOCAL0,
local1 => LOG_LOCAL1,
local2 => LOG_LOCAL2,
local3 => LOG_LOCAL3,
local4 => LOG_LOCAL4,
local5 => LOG_LOCAL5,
local6 => LOG_LOCAL6,
local7 => LOG_LOCAL7,
lpr => LOG_LPR,
mail => LOG_MAIL,
news => LOG_NEWS,
syslog => LOG_SYSLOG,
user => LOG_USER,
uucp => LOG_UUCP,
);
return exists $trans{$f} ? $trans{$f} : undef;
}
sub _transLevel ($) {
# Purpose: Translates the passed log level string into the syslog
# constant
# Returns: Constant scalar value
# Usage: $level = _transLevel($levelName);
my $l = lc shift;
my %trans = (
'debug' => LOG_DEBUG,
'info' => LOG_INFO,
'notice' => LOG_NOTICE,
'warn' => LOG_WARNING,
'warning' => LOG_WARNING,
'err' => LOG_ERR,
'error' => LOG_ERR,
'crit' => LOG_CRIT,
'critical' => LOG_CRIT,
'alert' => LOG_ALERT,
'emerg' => LOG_EMERG,
'emergency' => LOG_EMERG,
'panic' => LOG_EMERG,
);
return exists $trans{$l} ? $trans{$l} : undef;
}
{
my $sysopened = 0;
sub _openSyslog (;$$) {
# Purpose: If the syslogger hasn't been opened yet it opens it,
# otherwise exits cleanly.
# Returns: True (1) if successful,
# False (0) if there are any errors
# Usage: $rv = _openSyslog();
# Usage: $rv = _openSyslog($ident);
# Usage: $rv = _openSyslog($ident, $facility);
my $ident = shift;
my $facility = shift;
my $i = defined $ident ? $ident : 'undef';
my $f = defined $facility ? $facility : 'undef';
pdebug( "entering w/($i)($f)", PDLEVEL2 );
pIn();
# Open a handle to the syslog daemon
unless ($sysopened) {
# Make sure both values are set
$ident = _setIdent($ident);
$facility = 'user' unless defined $facility;
# Validate the facility
croak 'Can\'t open handle to syslogger with an invalid facility: '
. "$facility\n"
unless defined( $facility = _transFacility($facility) );
# Open the logger
openlog $ident, LOG_CONS | LOG_NDELAY | LOG_PID, $facility;
$sysopened = 1;
# TODO: trap return value of openlog?
}
pOut();
pdebug( "leaving w/rv: $sysopened", PDLEVEL2 );
return $sysopened;
}
sub remove (;$) {
# Purpose: Closes the syslogger
# Returns: True (1)
# Usage: remove();
pdebug( 'entering', PDLEVEL2 );
closelog();
$sysopened = 0;
pdebug( 'leaving w/rv: 1', PDLEVEL2 );
return 1;
}
}
sub log ($$$$$$$) {
# Purpose: Logs the passed message to the named file
# Returns: Return value of print()
# Usage: log($msgtime, $severity, $message, $name, $facility, $level,
# $scope);
# Usage: log($msgtime, $severity, $message, $name, $facility, $level,
# $scope, $progName);
my $msgtime = shift;
my $severity = shift;
my $message = shift;
my $name = shift;
my $facility = shift;
my $level = shift;
my $scope = shift;
my $rv = 0;
# Set defaults on optional args
$name = 'user' unless defined $name;
$severity = 'notice' unless defined $severity;
# Validate arguments
croak 'Mandatory second argument must be a valid severity'
unless defined _transLevel($severity);
croak 'Mandatory third argument must be a valid message'
unless defined $message;
croak 'Mandatory fourth argument must be a valid syslog facility'
unless defined _transFacility($name);
pdebug(
"entering w/($msgtime)($severity)($message)($name)"
. "($facility)($level)($scope)",
PDLEVEL1
);
pIn();
# TODO: Make sure prog name works?
# Make sure the logger is ready and log the message
if ( _openSyslog( undef, $name ) ) {
syslog _transLevel($severity), '%s', $message;
$rv = 1;
}
pOut();
pdebug( "leaving w/rv: $rv", PDLEVEL1 );
return $rv;
}
sub dump() {
# Purpose: Exists purely for compliance.
# Returns: True (1)
# Usage: init();
return ();
}
1;
__END__
=head1 NAME
Paranoid::Log::Syslog - Log Facility Syslog
=head1 VERSION
$Id: Syslog.pm,v 0.83 2010/06/03 19:04:07 acorliss Exp $
=head1 SYNOPSIS
use Paranoid::Log;
enableFacility('local3', 'syslog', 'debug', '+');
enableFacility('local3', 'syslog', 'debug', '+', 'my-daemon');
=head1 DESCRIPTION
This module implements UNIX syslog support for logging purposes. Which should
seem natural given that the entire B<Paranoid::Log> API is modeled closely
after it.
=head1 SUBROUTINES/METHODS
B<NOTE>: Given that this module is not intended to be used directly nothing
is exported.
=head2 init
=head2 log
=head2 remove
=head2 dump
=head1 DEPENDENCIES
=over
=item o
L<Paranoid::Debug>
=item o
L<Unix::Syslog>
=back
=head1 BUGS AND LIMITATIONS
Because we're keeping a connection to the syslogger open we don't support
enabling multiple facilities that log as different idents, etc. The first
syslog facility that gets activated will set those parameters.
=head1 AUTHOR
Arthur Corliss (corliss@digitalmages.com)
=head1 LICENSE AND COPYRIGHT
This software is licensed under the same terms as Perl, itself.
Please see http://dev.perl.org/licenses/ for more information.
(c) 2005, Arthur Corliss (corliss@digitalmages.com)
|