Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Sys::Syslog and LOG_EMERG

by pileofrogs (Priest)
on Aug 11, 2006 at 22:54 UTC ( #566971=perlquestion: print w/replies, xml ) Need Help??

pileofrogs has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying to use Sys::Syslog to log an emergency condition, but LOG_EMERG,"emergency","emerg" or even '0' doesn't work.

I'm on linux.

E.G.

use Sys::Syslog qw(:standard :macros); Sys::Syslog::syslog(LOG_EMERG,"%s","Foo");

produces this error:

syslog: invalid level/facility: 0 at ./test.pl line 11

I've tried lots of other log levels, like LOG_ALERT and LOG_NOTICE, and they work fine.

I can use the command line "logger" tool like this:

logger -p 0 -t test "Foo"

And it works fine.

Does anyone know what's going on here?

Thanks!
--Pileofrogs

Update: openlog() doesn't help.. see below

Another Update: I'm a total dufus. I have an old version of Sys::Syslog.

Replies are listed 'Best First'.
Re: Sys::Syslog and LOG_EMERG
by Maddingue (Sexton) on Aug 12, 2006 at 00:33 UTC

    (Also answering you here so the information is in PerlMonks as well.)

    You are using an old version of Sys::Syslog as this bug was fixed in version 0.14. Please update to the latest version.

    See also tickets #17518 (the real bug), and #20353 (same mistake as you).

Re: Sys::Syslog and LOG_EMERG
by Crackers2 (Parson) on Aug 11, 2006 at 23:04 UTC

    In short, RTFM...
    From the Sys::Syslog POD

    =head1 SYNOPSIS use Sys::Syslog; # all except setlogsock( +), or: use Sys::Syslog qw(:DEFAULT setlogsock); # default set, plus setl +ogsock() use Sys::Syslog qw(:standard :macros); # standard functions, pl +us macros setlogsock $sock_type; openlog $ident, $logopt, $facility; # don't forget this syslog $priority, $format, @args; $oldmask = setlogmask $mask_priority; closelog;

    Note the line marked "don't forget this"

    Basically, when logging to syslog you need both a priority and a facility. The command-line logger tool defaults to "user" as facility, but Sys::Syslog apparently does not, so you need the openlog call to set the facility.

    Update: Actually adding openlog doesn't seem to fix it, so that wasn't much help I'm afraid.

      hmmm... nice guess, but it still doesn't work.

      The code:

      use Sys::Syslog qw(:standard :macros); openlog('foo', '', 'user'); syslog(LOG_EMERG,"%s","Foo");

      ...produces the same error.

        Looks like a real bug in Sys::Syslog. Below the code from Syslog.pm around line 632:

        if ($_ eq 'kern' || $num <= 0) { croak "syslog: invalid level/facility: $_" }

        Changing this to

        if ($_ eq 'kern' || $num < 0) { croak "syslog: invalid level/facility: $_" }

        makes the code work for me.

        Update:Of course that change means you won't get an error message anymore if you forget to specify a priority (e.g. syslog(LOG_USER,"test")). I'm sure someone will come up with the right solution though.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://566971]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2020-01-19 12:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?