Question

We are sending a lot of syslog messages from our perls script using the facility code of local2. This works really well on Red Hat but on SunOS the messages don't appear to go to local2. For example, here is a minimal script

#!/usr/bin/perl

use strict;
use warnings;

use Sys::Syslog qw(:DEFAULT :standard :macros);
openlog("", 'ndelay', 'local2');
syslog('info', "ItWorks");
`logger -p local2.info "ItWorks"`;

In this script I am sending a log via the Syslog perl module and also via the logger command. Only the second message appears to go to local2. The reason I believe it is not going to local2 is that we have a rule setup in syslog.conf file to forward local2 and only the second message gets forwarded. When I look at the 2 messages in the log file they look slightly different, I'm not sure if that is important

Sep  2 11:41:22 ssapp7001v <150>Sep  2 11:41:22 d336599: ItWorks
Sep  2 11:41:22 ssapp7001v d336599: [ID 702911 local2.info] ItWorks

I should also add that I have tried various combinations in the perl code of using local2 as a string, as a constant, specifying it in the openlog call and/or in the syslog call. None of that appears to make any difference. I could just use backticks and call logger but that is my last resort because I then have to deal with characters that might not be command line friendly plus also the performance hit of opening a new process for every log message. Unfortunately making any config changes on this server is out of the question.

Was it helpful?

Solution

It looks like the Perl syslog module has some issues on SunOS. These issues might have been fixed but for me updating is not an option as this server is owned by another department in the company. What I ended up doing was just using the logger command line utility. This is far from ideal but does work. The code here closes the logger for each call but it could easily be kept open. The problem with keeping it open is that you can't change the severity.

open(my $fh, "| logger -p $facility.$severityName");
print $fh $logmsg . "\n";
close($fh);

The other option would be call the syslog API but I'm a bit over this and just need something that works at this stage :-)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top