Thread eval-Fehler des MainLoops abfangen (6 answers)
Opened by GoodFella at 2007-02-25 17:01

bloonix
 2007-02-26 14:14
#46248 #46248
User since
2005-12-17
1615 Artikel
HausmeisterIn
[Homepage]
user image
[quote=renee,26.02.2007, 12:38]
Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
# am Anfang des Programms:
$SIG{__WARN__} = \&warningToFile;

sub warningToFile{
 my $f;
 if(open($f, ">>",$error_log)){
     my($sec, $min, $hour, $mday, $mon, $year) = localtime(time);
     print $f (sprintf("%2d.%02d.%04d %02d:%02d:%02d   ", $mday, ($mon + 1), ($year + 1900), $hour, $min, $sec))."@_\n";
     close($f);
 }
 else{
   warn "Could not open $error_log!";
 }
}
[/quote]
Oder

Code: (dl )
1
2
3
4
5
6
7
8
9
use Log::Handler;

my $log = Log::Handler->new(
  filename => $error_log,
  mode => 'append'
);

$SIG{__WARN__} = sub { $log->warning(@_) };
$SIG{__DIE__}  = sub { $log->error(@_); exit(1) };


:p
What is a good module? That's hard to say.
What is good code? That's also hard to say.
One man's Thing of Beauty is another's man's Evil Hack.

View full thread eval-Fehler des MainLoops abfangen