I'm using a custom version of this module.
When I remove setlogsock, and I log an emergency event, my terminal doesn't return to a prompt unless I press enter.
I don't know if it works around the portability issue, but I wrapped the setlogsock call with:
if ( $^O ne 'MSWin32' ) { ... } . I haven't tested it.
I also added the ability to call the syslog severity levels what they're called, and their full names.
I added:
* "critical" to "crit" ("critic" isn't really a severity level)
* "informational" to "info").
* "emerg" and "emergency"
I've only tested this in a linux shell environment.
Patch attached.
I've also added the file I'm using to test on the command line.
--- /home/mvanwinkle/src/mvanwinkleias_github/ias_perl_script_infra/src/lib/perl5/Logger/Syslog.pm 2017-12-31 20:30:24.726432863 -0500
+++ Logger/Syslog.pm 2018-01-07 13:14:52.870359199 -0500
@@ -18,8 +18,31 @@
Logger::Syslog takes care of everything regarding the Syslog communication, all
you have to do is to use the function you need to send a message to syslog.
-Logger::Syslog provides one function per Syslog message level: debug, info,
-warning, error, notice, critic, alert.
+Logger::Syslog provides functions for each Syslog message level:
+
+=over 4
+
+=item debug
+
+=item info, informational
+
+=item warning
+
+=item err, error
+
+=item notice
+
+=item crit, critic, critical
+
+=item alert
+
+=item emerg, emergency
+
+=back
+
+The left most name (for example, example, 'crit') is what's passed to syslog.
+
+The right most name is the full english word.
=head1 NOTES
@@ -40,7 +63,7 @@
}
...
notice("There something to notify");
-
+
=cut
BEGIN {
@@ -50,12 +73,14 @@
@ISA = ( 'Exporter' ) ;
@EXPORT = qw (
&debug
- &info
+ &informational
¬ice
&warning
&error
- &critic
+ &critical
&alert
+ &emergency
+
&logger_prefix
&logger_close
&logger_init
@@ -96,7 +121,10 @@
$facility = $DEFAULT_FACILITY unless defined $facility;
eval {
- setlogsock('unix');
+ if ( $^O ne 'MSWin32' )
+ {
+ setlogsock('unix');
+ }
$fullname = __get_script_name();
openlog($fullname, 'pid', $facility);
logger_prefix("");
@@ -135,7 +163,7 @@
messages sent to syslog.
Example:
-
+
logger_prefix("my program");
info("starting");
...
@@ -159,7 +187,8 @@
warning => 'warn ',
debug => 'debug',
crit => 'crit ',
- alert => 'alert'
+ alert => 'alert',
+ emerg => 'emerg',
);
@@ -215,13 +244,28 @@
return if ($AUTOLOAD eq 'DESTROY');
return 0 unless defined $message and length $message;
- my @supported = qw(debug info warning err error notice alert crit critic);
+ my @supported = qw(
+ debug
+ info informational
+ warning
+ err error
+ notice
+ alert
+ crit critic critical
+ emerg emergency
+ );
if (grep /^$AUTOLOAD$/, @supported) {
my $level = $AUTOLOAD;
+ $level = 'info' if ($level eq 'informational');
+
$level = 'err' if ($level eq 'error');
+
$level = 'crit' if ($level eq 'critic');
+ $level = 'crit' if ($level eq 'critical');
+
+ $level = 'emerg' if ($level eq 'emergency');
log_with_syslog($level, $message);
}
#!/usr/bin/perl
use strict;
use warnings;
use lib './';
use Logger::Syslog();
# Logger::Syslog::
Logger::Syslog::debug("Debug message");
Logger::Syslog::alert("Alert message");
Logger::Syslog::info("Info message");
Logger::Syslog::informational("Informational message");
Logger::Syslog::notice("Notice message");
Logger::Syslog::warning("Warning message");
Logger::Syslog::err("Err message");
Logger::Syslog::error("Error message");
Logger::Syslog::crit("Crit message");
Logger::Syslog::critic("Critic message");
Logger::Syslog::critical("Critical message");
Logger::Syslog::emerg("Emerg message");
Logger::Syslog::emergency("Emergency message");
Logger::Syslog::debug("exiting.");
print "Exiting.\n";