#!/usr/bin/perl -w use strict; use diagnostics; use warnings; use Fcntl qw (:DEFAULT :flock); my %env = ('server_errorlog' => 'testerror.log',); if ($^O =~ /mswin/i) { $env{chmod_dateien} = 0666; } else { $env{chmod_dateien} = 0600; } ############################################################################### local $SIG{__WARN__} = sub { (my $error = shift) =~ s/[\r\n]//g; &errorlog_eintrag ($error,4); }; local $SIG{__DIE__} = sub { (my $error = shift) =~ s/[\r\n]//g; &errorlog_eintrag ($error,7); close (STDERR); }; # Hier Programm, dass Fehler macht my $a; my $b = $a + 3; # __WARN__ "Use of uninitialized value $a in addition (+) at sig.pl line ..." print "Bin noch da in " . __LINE__ . "\n"; if (1==2) { alarm (2); while (1==1) {} # __DIE__ "Terminating on signal SIGALRM(14)" } print "Bin noch da in " . __LINE__ . "\n"; if (1==1) { $a = 7/0; # __DIE__ "Illegal division by zero at sig.pl line ..." } print "Bin noch da in " . __LINE__ . "\n"; ############################################################################### sub errorlog_eintrag { my $meldung = shift; my $level = shift; my %apache_loglevel = ( 1 => 'debug', 2 => 'info', 3 => 'notice', 4 => 'warn', 5 => 'error', 6 => 'crit', 7 => 'alert', 8 => 'emerg', ); if (sysopen (my $errorlog,$env{server_errorlog},O_WRONLY|O_APPEND|O_CREAT,$env{chmod_dateien})) { print $errorlog '[' . localtime () . '] [' . $apache_loglevel{$level} .'] [client ' . (defined $ENV{'REMOTE_ADDR'} ? $ENV{'REMOTE_ADDR'} : 'localhost') . '] ' . $meldung . "\n"; close $errorlog; } }