X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FLXDebug.pm;h=17009ddcf04179ef9ae226cedba6d18d1f4706c3;hb=e770cd180600810fecd3554e104546236a9c9597;hp=abbb035db27a27fb1725542ba9150b4080023dab;hpb=5cc1afa0d90f96ca75957ddaa0032d2211052fe8;p=kivitendo-erp.git diff --git a/SL/LXDebug.pm b/SL/LXDebug.pm index abbb035db..17009ddcf 100644 --- a/SL/LXDebug.pm +++ b/SL/LXDebug.pm @@ -9,8 +9,9 @@ use constant TRACE => 1 << 4; use constant BACKTRACE_ON_ERROR => 1 << 5; use constant REQUEST_TIMER => 1 << 6; use constant WARN => 1 << 7; -use constant ALL => (1 << 8) - 1; -use constant DEVEL => INFO | QUERY | TRACE | BACKTRACE_ON_ERROR | REQUEST_TIMER; +use constant TRACE2 => 1 << 8; +use constant ALL => (1 << 9) - 1; +use constant DEVEL => INFO | DEBUG1 | QUERY | TRACE | BACKTRACE_ON_ERROR | REQUEST_TIMER; use constant FILE_TARGET => 0; use constant STDERR_TARGET => 1; @@ -88,7 +89,7 @@ sub enter_sub { my $level = shift || 0; 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 if $level && !($global_level & TRACE2); # ignore if level of trace isn't active my ($package, $filename, $line, $subroutine) = caller(1); my ($dummy1, $self_filename, $self_line) = caller(0); @@ -112,13 +113,13 @@ sub leave_sub { my $level = shift || 0; 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 if $level && !($global_level & TRACE2); # ignore if level of trace isn't active my ($package, $filename, $line, $subroutine) = caller(1); my ($dummy1, $self_filename, $self_line) = caller(0); my $indent = " " x --$self->{"calldepth"}; - my $time = $self->want_request_timer ? $self->get_request_time : ''; + my $time = $self->want_request_timer ? $self->get_request_time || '' : ''; if (!defined($package)) { $self->_write('sub' . $level, $indent . "/ $time top-level?\n"); @@ -156,7 +157,7 @@ sub warn { } sub dump { - my ($self, $level, $name, $variable) = @_; + my ($self, $level, $name, $variable, %options) = @_; if ($data_dumper_available) { my $password; @@ -167,7 +168,10 @@ sub dump { my $dumper = Data::Dumper->new([$variable]); $dumper->Sortkeys(1); - $self->message($level, "dumping ${name}:\n" . $dumper->Dump()); + $dumper->Indent(2); + $dumper->$_($options{$_}) for keys %options; + my $output = $dumper->Dump(); + $self->message($level, "dumping ${name}:\n" . $output); $variable->{password} = $password if (defined $password); @@ -178,10 +182,14 @@ sub dump { keys %{ $variable }; } + return $output; + } else { $self->message($level, "dumping ${name}: Data::Dumper not available; " . "variable cannot be dumped"); + + return undef; } } @@ -261,7 +269,7 @@ sub _write { chomp($message); if ((FILE_TARGET == $self->{"target"}) - && open(FILE, ">>" . $self->{"file"})) { + && open(FILE, ">>", $self->{"file"})) { print(FILE "${date}${message}\n"); close(FILE); @@ -291,9 +299,9 @@ sub end_request { } sub log_time { - my $self = shift; + my ($self, @slurp) = @_; return 1 unless want_request_timer(); - $self->_write("time", $self->get_request_time); + $self->_write("time", $self->get_request_time() . (@slurp ? " (@slurp)" : '')); } sub get_request_time { @@ -339,11 +347,11 @@ __END__ =head1 NAME -LXDebug - Lx-Office debugging facilities +LXDebug - kivitendo debugging facilities =head1 SYNOPSIS -This module provides functions for debugging Lx-Office. An instance is +This module provides functions for debugging kivitendo. An instance is always created as the global variable C<$::lxdebug> at the earliest possible moment. @@ -382,7 +390,15 @@ Log all queries executed by the L utility methods. =item C -Log sub calls and exits via the L/L functions. +Log sub calls and exits via the L/L functions, +but only if they're called with a log level that is falsish +(e.g. none, C, 0). + +=item C + +Log sub calls and exits via the L/L functions +even if they're called with a log level of 2. Will only have an effect +if C is set as well. =item C @@ -406,6 +422,57 @@ Shortcut for C. =back +=head1 CONFIGURATION + +C gets its configuration from the C<[debug]> section of +the C configuration file. The available options +are: + +=over 4 + +=item C + +A string of log level names that should be activated by +default. Multiple log levels are separated by C<|>. + +=item C + +A boolean (C<1> or C<0>). Turns on the C<$::form> watch facility. If +this is enabled then any key inside C<$::form> can be monitored for +changes. For example: + + # Start watching 'action' + $::form->{"Watchdog::action"} = 1; + # Stop watching 'invtotal' + $::form->{"Watchdog::invtotal"} = 0; + +A log message is written when the watchdog is enabled for a variable +and for each subsequent change. The log message includes the place +(file name and line number) of the instruction changing the key. + +Note that this entails a performance penalty. Also only the keys +themselves are monitored -- not the references they point to. E.g. the +following would not trigger a change: + + $::form->{"Watchdog::some_hash"} = 1; + # Does not trigger: + $::form->{some_hash}->{some_value} = 42; + # This does trigger: + $::form->{some_hash} = { something => 'else' }; + +=item C + +A boolean (C<1> or C<0>). If turned on then certain temporary files +are not removed but kept in the C directory. These include the +temporary files used during printing, e.g. LaTeX files. + +=item C + +The path and file name of the debug log file. Must be a location +writeable by the web server process. + +=back + =head1 FUNCTIONS =over 4 @@ -418,8 +485,8 @@ Pairs of these can be put near the beginning/end of a sub. They'll cause a trace to be written to the log file if the C level is active. -If C<$level> is given then the log messages will only be logged if an -additional log level C<$level> is active as well. +If C<$level> is given then the log messages will only be logged if the +global log level C is active as well. =item C