http://www.perlmonks.org?node_id=72921

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 syslog.pl (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 = "local0.info"; 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 progname.pl: : 1.1 $ Apr 16 15:21:14 hopper progname.pl: : 1.1 $ Apr 16 15:21:14 hopper progname.pl: : 1.1 $ Apr 16 15:25:34 hopper progname.pl: : 1.1 $ Apr 16 15:42:31 hopper progname.pl: : 1.1 $ Apr 16 15:46:14 hopper progname.pl: : 1.1 $ Apr 16 15:49:20 hopper progname.pl: : 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