Hello,

I wanted to have spamd print logging messages on stderr (or stdout) so that
I could use multilog program for logging instead of syslog.

Attached is a patch to do just that.
--- /usr/local/bin/spamd        Mon Jul  8 14:56:42 2002
+++ spamd       Mon Jul  8 15:53:35 2002
@@ -19,6 +19,7 @@
 use POSIX qw(setsid);
 use Getopt::Long;
 use Pod::Usage;
+use IO::Handle;
 use POSIX ":sys_wait_h";
 
 my %resphash = (
@@ -43,6 +44,8 @@
 # defaults
 my %opt = ('user-config' => 1);
 
+autoflush STDERR 1;
+
 Getopt::Long::Configure ("bundling");
 GetOptions(
        'auto-whitelist|whitelist|a' => \$opt{'auto-whitelist'},
@@ -204,6 +207,7 @@
     warn "server started on port $port\n";
     warn "server pid: $$\n";
 }
+
 logmsg "server started on port $port";
 
 for ( ; ($paddr = accept(Client,Server)) ; close Client)
@@ -622,6 +626,15 @@
 
 sub logmsg
 {
+  if($log_facility =~ /stderr/i) {
+    print STDERR @_;
+    print STDERR "\n" unless(substr($_[-1], -1) eq "\n");
+  }
+  elsif($log_facility =~ /stdout/i) {
+    print STDOUT @_;
+    print STDOUT "\n" unless(substr($_[-1], -1) eq "\n");
+  }
+  else {
     my $old = $SIG{'PIPE'};
     $SIG{'PIPE'} = sub { $main::SIGPIPE_RECEIVED++; };
     
@@ -653,6 +666,7 @@
     }
 
     $SIG{'PIPE'} = $old if defined($old);
+  }
 }
 
 sub kill_handler
@@ -708,7 +722,8 @@
  -p port, --port                    Listen on specified port (default: 783)
  -q, --sql-config                   Enable SQL config (only useful with -x)
  -r pidfile, --pidfile              Write the process id to pidfile
- -s facility, --syslog=facility     Specify the syslog facility (default: mail)
+ -s facility, --syslog=facility     Specify the syslog facility (default: mail).
+                                    You can specify stderr or stdout to print to 
+STDERR/STDOUT
  -u username, --username=username   Run as username
  -v, --vpopmail                     Enable vpopmail config
  -x, --nouser-config                Disable user config files

Attachment: msg07173/pgp00000.pgp
Description: PGP signature

Reply via email to