$| = 1;
# import from fex.pp
-our ($tmpdir,$logdir,$timeout,$fra,$bs);
+our ($tmpdir,@logdir,$timeout,$fra,$bs);
# load common code, local config: $HOME/lib/fex.ph
require "$FEXLIB/fex.pp" or die "$0: cannot load $FEXLIB/fex.pp - $!\n";
chdir $spooldir or error(500,"$spooldir - $!");
-my $debuglog = "$tmpdir/sex.log";
+# my $debuglog = "$tmpdir/sex.log";
my $ra = $ENV{REMOTE_ADDR}||0;
$fra .= '/'.$ENV{HTTP_X_FORWARDED_FOR} if $ENV{HTTP_X_FORWARDED_FOR};
$timeout *= 10;
}
sub sexlog {
- if (open my $log,'>>',"$logdir/sex.log") {
- flock $log,LOCK_EX;
- seek $log,0,SEEK_END;
- printf {$log} "%s [%s_%s] %s (%s) %s\n",
- isodate(time),$$,$ENV{REQUESTCOUNT},$user,$fra,"@_";
- close $log;
+ my $msg = "@_";
+
+ $msg =~ s/\n/ /g;
+ $msg =~ s/\s+$//;
+ $msg = sprintf "%s [%s_%s] %s (%s) %s\n",
+ isodate(time),$$,$ENV{REQUESTCOUNT},$user,$fra,$msg;
+
+ foreach my $log (@logdir) {
+ if (open $log,'>>',"$log/sex.log") {
+ flock $log,LOCK_EX;
+ seek $log,0,SEEK_END;
+ printf {$log} $msg;
+ close $log;
+ }
}
}
sub sigexit {
my ($sig) = @_;
- if (open my $log,'>>',"$logdir/sex.log") {
- printf {$log} "%s %s (%s) caught SIGNAL %s\n",
- isodate(time),$user||'-',$fra||'-',"@_";
- close $log;
+ my $msg = "@_";
+
+ $msg =~ s/\n/ /g;
+ $msg =~ s/\s+$//;
+ $msg = sprintf "%s %s (%s) caught SIGNAL %s\n",
+ isodate(time),$user||'-',$fra||'-',$msg;
+
+ foreach my $log (@logdir) {
+ if (open $log,'>>',"$log/sex.log") {
+ flock $log,LOCK_EX;
+ seek $log,0,SEEK_END;
+ printf {$log} $msg;
+ close $log;
+ }
}
if ($sig eq 'DIE') {
shift;