Mehr Debugmöglichkeiten für DBUtils.pm und allgemein für Fehlersituationen eingeführt...
[kivitendo-erp.git] / SL / LXDebug.pm
index 8a4dd29..f59e610 100644 (file)
@@ -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 CALL_TRACE_ON_ERROR => 32;
+use constant ALL                 => 63;
 
 use constant FILE_TARGET   => 0;
 use constant STDERR_TARGET => 1;
@@ -99,6 +100,21 @@ sub leave_sub {
   return 1;
 }
 
+sub full_error_call_trace {
+  my ($self) = @_;
+
+  return 1 unless ($global_level & CALL_TRACE_ON_ERROR);
+
+  $self->message(CALL_TRACE_ON_ERROR, "Starting full caller dump:");
+  my $level = 0;
+  while (my ($dummy, $filename, $line, $subroutine) = caller $level) {
+    $self->message(CALL_TRACE_ON_ERROR, "${subroutine} from ${filename}:${line}");
+    $level++;
+  }
+
+  return 1;
+}
+
 sub message {
   my ($self, $level, $message) = @_;
 
@@ -146,7 +162,7 @@ sub _write {
 
 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;