X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FLXDebug.pm;h=6da1a72724cf690ccfc1cb10d8b6e45379f9d602;hb=4311578257aa2e5808580def7e80a38d493646b0;hp=59a6579d27b2f56375d1d9242d8857be08501967;hpb=6c38a7cfc8b4cf831da178101b3ae2fc83596081;p=kivitendo-erp.git diff --git a/SL/LXDebug.pm b/SL/LXDebug.pm index 59a6579d2..6da1a7272 100644 --- a/SL/LXDebug.pm +++ b/SL/LXDebug.pm @@ -1,12 +1,13 @@ package LXDebug; -use constant NONE => 0; -use constant INFO => 1; -use constant DEBUG1 => 2; -use constant DEBUG2 => 4; -use constant QUERY => 8; -use constant TRACE => 16; -use constant ALL => 31; +use constant NONE => 0; +use constant INFO => 1; +use constant DEBUG1 => 2; +use constant DEBUG2 => 4; +use constant QUERY => 8; +use constant TRACE => 16; +use constant BACKTRACE_ON_ERROR => 32; +use constant ALL => 63; use constant FILE_TARGET => 0; use constant STDERR_TARGET => 1; @@ -15,11 +16,15 @@ use POSIX qw(strftime); my $data_dumper_available; +our $global_level; +our $watch_form; + BEGIN { eval("use Data::Dumper"); $data_dumper_available = $@ ? 0 : 1; $global_level = NONE; + $watch_form = 0; } sub new { @@ -95,8 +100,24 @@ sub leave_sub { return 1; } +sub show_backtrace { + my ($self) = @_; + + return 1 unless ($global_level & BACKTRACE_ON_ERROR); + + $self->message(BACKTRACE_ON_ERROR, "Starting full caller dump:"); + my $level = 0; + while (my ($dummy, $filename, $line, $subroutine) = caller $level) { + $self->message(BACKTRACE_ON_ERROR, " ${subroutine} from ${filename}:${line}"); + $level++; + } + + return 1; +} + sub message { my ($self, $level, $message) = @_; + $self->_write(level2string($level), $message) if (($self->{"level"} | $global_level) & $level || !$level); } @@ -134,14 +155,14 @@ sub _write { print(FILE "${date}${message}\n"); close(FILE); - } elsif (STDERR_TARGET == $self->{"target"}) { + } elsif (STDERR_TARGET == $self->{"target"}) { print(STDERR "${date}${message}\n"); } } sub level2string { # use $_[0] as a bit mask and return levelstrings separated by / - join '/', qw(info debug1 debug2 query trace)[ grep { (reverse split //, sprintf "%05b", $_[0])[$_] } 0..4 ] + join '/', qw(info debug1 debug2 query trace error_call_trace)[ grep { (reverse split //, sprintf "%05b", $_[0])[$_] } 0..5 ] } 1;