Subject: | Patch to remove/edit PID output |
Here is a patch to allow the user to remove or edit the PID output in syslog messages. Some of the scripts I have that output syslog messages don't need to have the PID as well, and other people complain about it sometimes. :)
The patch allows you to set 'Pid' to any number (Like if you are doing syslog stuff for another process), and anything that isn't a number will result in no PID at all.
--- Syslog.pm.orig 2003-08-11 17:02:49.000000000 -0400
+++ Syslog.pm 2003-08-11 17:22:04.000000000 -0400
@@ -60,8 +60,9 @@
my $self = { Name => $name,
Facility => 'local5',
Priority => 'err',
+ Pid => $$,
SyslogPort => 514,
- SyslogHost => '127.0.0.1'};
+ SyslogHost => '127.0.0.1'};
bless $self,$class;
my %par = @_;
foreach (keys %par){
@@ -79,7 +80,7 @@
$local{$_}=$par{$_};
}
- my $pid=$$;
+ my $pid=($local{Pid} =~ /^\d+$/) ? "\[$local{Pid}\]" : "";
my $facility_i=$syslog_facilities{$local{Facility}};
my $priority_i=$syslog_priorities{$local{Priority}};
@@ -91,7 +92,7 @@
}
my $d=(($facility_i<<3)|($priority_i));
- my $message = "<$d>$local{Name}\[$pid\]: $msg";
+ my $message = "<$d>$local{Name}$pid: $msg";
my $sock=new IO::Socket::INET(PeerAddr => $local{SyslogHost},
PeerPort => $local{SyslogPort},
@@ -134,6 +135,7 @@
Name <calling script name>
Facility local5
Priority err
+ Pid $$
SyslogPort 514
SyslogHost 127.0.0.1
@@ -144,6 +146,7 @@
Valid Priorities are:
emerg, alert, crit, err, warning, notice, info, debug
+Set Pid to any non numeric value to disable in the output.
=head1 AUTHOR