perl
view release on metacpan or search on metacpan
cpan/Sys-Syslog/Syslog.pm view on Meta::CPAN
EVENTLOG: {
my $verbose_if_Win32 = $^O =~ /Win32/i;
if (can_load_sys_syslog_win32($verbose_if_Win32)) {
unshift @connectMethods, 'eventlog';
}
}
my @defaultMethods = @connectMethods;
my @fallbackMethods = ();
# The timeout in connection_ok() was pushed up to 0.25 sec in
# Sys::Syslog v0.19 in order to address a heisenbug on MacOSX:
# http://london.pm.org/pipermail/london.pm/Week-of-Mon-20061211/005961.html
#
# However, this also had the effect of slowing this test for
# all other operating systems, which apparently impacted some
# users (cf. CPAN-RT #34753). So, in order to make everybody
# happy, the timeout is now zero by default on all systems
# except on OSX where it is set to 250 msec, and can be set
# with the infamous setlogsock() function.
#
# Update 2011-08: this issue is also been seen on multiprocessor
# Debian GNU/kFreeBSD systems. See http://bugs.debian.org/627821
# and https://rt.cpan.org/Ticket/Display.html?id=69997
# Also, lowering the delay to 1 ms, which should be enough.
$sock_timeout = 0.001 if $^O =~ /darwin|gnukfreebsd/;
# Perl 5.6.0's warnings.pm doesn't have warnings::warnif()
if (not defined &warnings::warnif) {
*warnings::warnif = sub {
goto &warnings::warn if warnings::enabled(__PACKAGE__)
}
}
# coderef for a nicer handling of errors
my $err_sub = $options{nofatal} ? \&warnings::warnif : \&croak;
sub AUTOLOAD {
# This AUTOLOAD is used to 'autoload' constants from the constant()
# XS function.
no strict 'vars';
my $constname;
($constname = $AUTOLOAD) =~ s/.*:://;
croak "Sys::Syslog::constant() not defined" if $constname eq 'constant';
my ($error, $val) = constant($constname);
croak $error if $error;
no strict 'refs';
*$AUTOLOAD = sub { $val };
goto &$AUTOLOAD;
}
sub openlog {
($ident, my $logopt, $facility) = @_;
# default values
$ident ||= basename($0) || getlogin() || getpwuid($<) || 'syslog';
$logopt ||= '';
$facility ||= LOG_USER();
for my $opt (split /\b/, $logopt) {
$options{$opt} = 1 if exists $options{$opt}
}
$err_sub = delete $options{nofatal} ? \&warnings::warnif : \&croak;
return 1 unless $options{ndelay};
connect_log();
}
sub closelog {
disconnect_log() if $connected;
$options{$_} = 0 for keys %options;
$facility = $ident = "";
$connected = 0;
return 1
}
sub setlogmask {
my $oldmask = $maskpri;
$maskpri = shift unless $_[0] == 0;
$oldmask;
}
my %mechanism = (
console => {
check => sub { 1 },
},
eventlog => {
check => sub { return can_load_sys_syslog_win32() },
err_msg => "no Win32 API available",
},
inet => {
check => sub { 1 },
},
native => {
check => sub { 1 },
},
pipe => {
check => sub {
($syslog_path) = grep { defined && length && -p && -w _ }
$syslog_path, &_PATH_LOG, "/dev/log";
return $syslog_path ? 1 : 0
},
err_msg => "path not available",
},
stream => {
check => sub {
if (not defined $syslog_path) {
my @try = qw(/dev/log /dev/conslog);
unshift @try, &_PATH_LOG if length &_PATH_LOG;
($syslog_path) = grep { -w } @try;
}
return defined $syslog_path && -w $syslog_path
},
err_msg => "could not find any writable device",
},
( run in 0.990 second using v1.01-cache-2.11-cpan-8f98c5d2c55 )