Thread Manipulierung von __DIE__ und __WARN__ (17 answers)
Opened by bloonix at 2007-06-05 13:45

bloonix
 2007-06-06 10:59
#77255 #77255
User since
2005-12-17
1615 Artikel
HausmeisterIn
[Homepage]
user image
[quote=Strat,06.06.2007, 01:18]nein, weitere debug-informationen, die ich manchmal beschaffe; und da brauche ich z.B. Dateinamen und Zeilennummer in variablen, da hilft mir confess oder so nicht...[/quote]
wie wäre es mit

Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
use strict;
use warnings;
use Log::Handler;

my $log = Log::Handler->new(
  filename => \*STDERR,
  newline => 1
);

$SIG{__DIE__} = sub { $log->trace(@_); exit(9); };

die "here we die";


Ausgabe:

Code: (dl )
1
2
3
4
5
6
# ./foo.pl 
Jun 06 08:57:05 [TRACE] here we die at ./foo.pl line 13.
  CALL(3): package(main) filename(./foo.pl) line(13) subroutine(main::__ANON__) hasargs(1) wantarray(0)
  CALL(2): package(main) filename(./foo.pl) line(11) subroutine(Log::Handler::trace) hasargs(1)
  CALL(1): package(Log::Handler) filename(/usr/local/share/perl/5.8.8/Log/Handler.pm) line(959) subroutine(Log::Handler::_print) hasargs(1)
  CALL(0): package(Log::Handler) filename(/usr/local/share/perl/5.8.8/Log/Handler.pm) line(1110) subroutine(Devel::Backtrace::new) hasargs(1) wantarray(0)


oder mit debug_mode => 2

Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
Jun 06 08:59:54 [TRACE] here we die at ./foo.pl line 14.
  CALL(3):
     package     main
     filename    ./foo.pl
     line        14
     subroutine  main::__ANON__
     hasargs     1
     wantarray   0
  CALL(2):
     package     main
     filename    ./foo.pl
     line        12
     subroutine  Log::Handler::trace
     hasargs     1
  CALL(1):
     package     Log::Handler
     filename    /usr/local/share/perl/5.8.8/Log/Handler.pm
     line        959
     subroutine  Log::Handler::_print
     hasargs     1
  CALL(0):
     package     Log::Handler
     filename    /usr/local/share/perl/5.8.8/Log/Handler.pm
     line        1110
     subroutine  Devel::Backtrace::new
     hasargs     1
     wantarray   0
\n\n

<!--EDIT|opi|1181113264-->
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 Manipulierung von __DIE__ und __WARN__