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;
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 {
$self->{"file"} = "/tmp/lx-office-debug.log";
$self->{"target"} = FILE_TARGET;
$self->{"level"} = 0;
- $self->{"watchedvars"} = {};
while ($_[0]) {
$self->{ $_[0] } = $_[1];
my ($self, $level) = @_;
$level *= 1;
- $self->check_watched_form_variables();
-
return 1 unless ($global_level & TRACE); # ignore if traces aren't active
return 1 if $level && !($global_level & $level); # ignore if level of trace isn't active
my ($self, $level) = @_;
$level *= 1;
- $self->check_watched_form_variables();
-
return 1 unless ($global_level & TRACE); # ignore if traces aren't active
return 1 if $level && !($global_level & $level); # ignore if level of trace isn't active
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->check_watched_form_variables();
$self->_write(level2string($level), $message) if (($self->{"level"} | $global_level) & $level || !$level);
}
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 ]
-}
-
-sub watch_form_variable {
- my ($self, $var) = @_;
-
- $self->{"watchedvars"}->{$var} = $main::form->{$var};
- $self->_write("WATCH", "Adding \$form->{$var} with current value \"$main::form->{$var}\"");
-}
-
-sub check_watched_form_variables {
- my ($self) = @_;
-
- return unless $main::form;
-
- foreach my $var (sort(keys(%{ $self->{"watchedvars"} }))) {
- if ($main::form->{$var} ne $self->{"watchedvars"}->{$var}) {
- $self->_write("WATCH", "Variable \$form->{$var} changed from \"" .
- $self->{"watchedvars"}->{$var} . "\" to \"" .
- $main::form->{$var} . "\"");
- $self->{"watchedvars"}->{$var} = $main::form->{$var};
- }
- }
+ join '/', qw(info debug1 debug2 query trace error_call_trace)[ grep { (reverse split //, sprintf "%05b", $_[0])[$_] } 0..5 ]
}
1;