X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FLXDebug.pm;h=b24372445157402e1726d6e9b1dbfa52642a6eb5;hb=9a7a811d2d254f95f3cf1664566ff4a5335eee31;hp=e3778d44fd9f9d6e0684d7c0e35cbb783b7cd089;hpb=8fac2b08f248b7db54c6937c2ab154805aae63d4;p=kivitendo-erp.git diff --git a/SL/LXDebug.pm b/SL/LXDebug.pm index e3778d44f..b24372445 100644 --- a/SL/LXDebug.pm +++ b/SL/LXDebug.pm @@ -8,7 +8,8 @@ use constant QUERY => 1 << 3; use constant TRACE => 1 << 4; use constant BACKTRACE_ON_ERROR => 1 << 5; use constant REQUEST_TIMER => 1 << 6; -use constant ALL => (1 << 7) - 1; +use constant WARN => 1 << 7; +use constant ALL => (1 << 8) - 1; use constant DEVEL => INFO | QUERY | TRACE | BACKTRACE_ON_ERROR | REQUEST_TIMER; use constant FILE_TARGET => 0; @@ -38,6 +39,8 @@ sub new { my $type = shift; my $self = {}; + _init_globals_from_config(); + $self->{"calldepth"} = 0; $self->{"file"} = $file_name || "/tmp/lx-office-debug.log"; $self->{"target"} = FILE_TARGET; @@ -52,6 +55,22 @@ sub new { bless($self, $type); } +my $globals_inited_from_config; +sub _init_globals_from_config { + return if $globals_inited_from_config; + $globals_inited_from_config = 1; + + my $cfg = $::lx_office_conf{debug} || {}; + + $global_level = NONE() if $cfg->{global_level} =~ /NONE/; + foreach my $level (grep { $_} split(m/\s+/, $cfg->{global_level})) { + $global_level |= eval "${level}()"; + } + + $watch_form = $cfg->{watch_form}; + $file_name = $cfg->{file_name} || "/tmp/lx-office-debug.log"; +} + sub set_target { my ($self, $target, $file) = @_; @@ -65,8 +84,8 @@ sub set_target { } sub enter_sub { - my ($self, $level) = @_; - $level *= 1; + my $self = shift; + 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 @@ -89,8 +108,8 @@ sub enter_sub { } sub leave_sub { - my ($self, $level) = @_; - $level *= 1; + my $self = shift; + 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 @@ -125,10 +144,16 @@ sub show_backtrace { } sub message { + no warnings; my ($self, $level, $message) = @_; $self->_write(level2string($level), $message) if (($self->{"level"} | $global_level) & $level || !$level); } +sub warn { + no warnings; + my ($self, $message) = @_; + $self->message(WARN, $message); +} sub dump { my ($self, $level, $name, $variable) = @_; @@ -210,6 +235,7 @@ sub is_tracing_enabled { } sub _write { + no warnings; my ($self, $prefix, $message) = @_; my $date = strftime("%Y-%m-%d %H:%M:%S $$ [" . getppid() . "] ${prefix}: ", localtime(time())); local *FILE; @@ -227,8 +253,9 @@ sub _write { } sub level2string { + no warnings; # use $_[0] as a bit mask and return levelstrings separated by / - join '/', qw(info debug1 debug2 query trace error_call_trace)[ grep { (reverse split //, sprintf "%05b", $_[0])[$_] } 0..5 ] + join '/', qw(info debug1 debug2 query trace error_call_trace request_timer WARNING)[ grep { (reverse split //, sprintf "%08b", $_[0])[$_] } 0..7 ] } sub begin_request {