Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

syslog logging

by snafu (Chaplain)
on Apr 17, 2001 at 00:09 UTC ( #72921=perlquestion: print w/replies, xml ) Need Help??
snafu has asked for the wisdom of the Perl Monks concerning the following question:

I can't use Sys::Syslog yet. I can't use (same problem as Sys::Syslog (missing subroutine called &DEBUG_LOG)) which I am pretty sure that if I wanted to fix this I'd have to upgrade Perl. Since I am not the admin of this box and since I had to pull teeth just to get Perl on this machine *and* since the admin refuses to put anything on the box that is not from Sun I am forced to make do. All is well, at least I have Perl on the box.
So, I am resorting to using /usr/bin/logger (solaris 7 box). Therefore, here is what I am doing so far but it is not working.

The Perl version I am using currently:

This is perl, version 5.004_02

sub logit($$$) { my ($type, $severity, $msg) = @_ ; my $facility = ""; if ( !defined($type) or !defined($severity) or !defined($msg) ) { $type ||= "undefined"; $severity ||= "undefined"; $msg ||= "undefined"; print STDERR " In order to use the logit subroutine the caller mus +t provide\n"; print STDERR " three arguments: type, severity, and the message!!! +\n"; print "(type: $type | severity: $severity | msg: $msg)\n\n"; print LOG &timestamp . ": Exited! Error in $plProgName - caller d +id not properly\n"; print LOG &timestamp . ": call subroutine \&logit!\n"; print LOG &timestamp . ": (type: $type | severity: $severity | msg +: $msg)\n"; exit(1); }
open(SYSLOG,"| /usr/bin/logger -p $facility -t $plProgName $REVISION");
print "/usr/bin/logger -p $facility -t $plProgName $REVISION\n"; # debug line only
for ( split(/:/,$type) ) { switch: { /syslog/ && do { # Print only to syslog here print "(type: $type | severity: $severity | msg: $msg)\n\n"; print SYSLOG "$severity - $msg"; last switch; }; /stdout/ && do { # Print only to stdout here print("$severity - $msg\n"); last switch; }; /stderr/ && do { # Print only to stderr here print STDERR "$severity - $msg\n"; last switch; }; /log/ && do { # Print to the log file here print LOG &timestamp . ": $severity - $msg\n"; last switch; }; /all/ && do { # Print to everything here (except stderr) for ( *STDOUT, *LOG, *SYSLOG ) { print $_ &timestamp . ": $severity - $msg ($_)\n"; } last switch; }; /allerr/ && do { # Print to everything here (except stdout) for ( *STDERR, *LOG, *SYSLOG ) { print $_ &timestamp . ": $severity - $msg ($_)\n"; } last switch; }; # This next line is simply for completeness. It will most likely # never get used because of the check in the beginning of this # sub. DEFAULT: { print LOG &timestamp . ": $severity - $msg\n"; print STDOUT "$severity - $msg\n" if ( $DEBUG == "1" ); # Print only to the log here }; } } close(SYSLOG); }

The script doesn't break but the logging to the syslog facility does not work. I know it is because of the pipe but I can't think of a better way to do it. I have always been taught that I have to pipe the command in an open but is that really necessary? The output in the syslog file is:

Apr 16 15:19:24 hopper : 1.1 $ Apr 16 15:21:14 hopper : 1.1 $ Apr 16 15:21:14 hopper : 1.1 $ Apr 16 15:25:34 hopper : 1.1 $ Apr 16 15:42:31 hopper : 1.1 $ Apr 16 15:46:14 hopper : 1.1 $ Apr 16 15:49:20 hopper : 1.1 $

TIA! PS - I wrote this sub routine and I am pretty happy with it. If others could give me comments on it I would really appreciate it. Thanks!

- Jim

Replies are listed 'Best First'.
Re: syslog logging
by lhoward (Vicar) on Apr 17, 2001 at 02:37 UTC
    Another option would be to use Net::Syslog to send messages to your syslog. You can either install it locally (under your account) or just steal code from it to include in your programs (its pretty short). It provides a pure-perl interface to the syslog forwarding protocol, so as long as your local syslogd is configured to accept forwarded syslogs (I think the default on solaris is to, I know on Linux the default is not to) you should have no problems getting it going.
Re: syslog logging
by AgentM (Curate) on Apr 17, 2001 at 00:19 UTC
    Yikes. Bad idea. The logger daemon probably doesn't like what you're sending it. Reverse engineering what is supposed to be passed would be A solution, bu the easiest solution is probably to make your own perlxs binds to the C lib that allows for logging. You need only one function. Good luck!
    AgentM Systems nor Nasca Enterprises nor Bone::Easy nor Macperl is responsible for the comments made by AgentM. Remember, you can build any logical system with NOR.
      Wow. This is something totally new to me. I will have to read up on it. For now, I think I will stick with the system() but I know I will be checking into this perlxs more. I am going to have to study this man page.

      Thanks Agent!

      - Jim

Re: syslog logging
by snafu (Chaplain) on Apr 17, 2001 at 00:20 UTC
    Hmm. I think I figured it out guys. I replaced the open() with system() calls instead. I will wait for further light and knowledge. :)

    - Jim

Re: syslog logging
by princepawn (Parson) on Apr 17, 2001 at 00:56 UTC
    I can't use Sys::Syslog yet. I can't use (same problem as Sys::Syslog (missing subroutine called &DEBUG_LOG)) which I am pretty sure that if I wanted to fix this I'd have to upgrade Perl.

    What happened is that when Perl was installed and h2ph was run to turn C header files into Perl subroutines, this one conversion was botched.

    If you have root access you might be able to patch it somehow.

      I checked this possibility and have found that it isn't the ph file. That is the odd part. The subroutine is in the module itself. I admit, the installation of the perl we have for this box is a lil screwy I think. I appreciate the advice though. Unfortunately, this isn't the cause of my problem. I do believe that it has something to do with how the module was installed though. I think there is something else missing from my copy of the module. I intend to try AgentM's idea and try perlxs out.

      - Jim

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2018-10-18 17:38 GMT
Find Nodes?
    Voting Booth?
    When I need money for a bigger acquisition, I usually ...

    Results (103 votes). Check out past polls.