X-Git-Url: http://dxcluster.net/gitweb/gitweb.cgi?a=blobdiff_plain;f=perl%2FDXDebug.pm;h=83e49259863e0f7259cfcae0fa4702e536d7a2a6;hb=5094a0b55d903d344277adf9d26b5af8e37247d8;hp=3b2e4b2cc222cbbd7378c4154f8815127bc409a4;hpb=f4ce9b1afbcaeda10e0497b0d2b33fef0a4a5245;p=spider.git diff --git a/perl/DXDebug.pm b/perl/DXDebug.pm index 3b2e4b2c..83e49259 100644 --- a/perl/DXDebug.pm +++ b/perl/DXDebug.pm @@ -28,7 +28,7 @@ use 5.10.1; require Exporter; @ISA = qw(Exporter); -@EXPORT = qw(dbginit dbg dbgadd dbgsub dbglist dbgdump isdbg dbgclose dbgtrace confess croak cluck carp); +@EXPORT = qw(dbginit dbg dbgadd dbgsub dbglist dbgdump isdbg dbgclose dbgtrace dbgprintring dbgsetcat confess croak cluck carp); use strict; use vars qw(%dbglevel $fp $callback $cleandays $keepdays $dbgringlth); @@ -69,12 +69,12 @@ if (!defined $DB::VERSION) { exit(-1); } sub carp { - DXDebug::dbgprintring(25) if DXDebug('nologchan'); + DXDebug::dbgprintring(5) if DXDebug::isdbg('nologchan'); # DXDebug::dbg(Carp::shortmess(\@_)); DXDebug::longmess(\@_); } sub cluck { - DXDebug::dbgprintring(25) if DXDebug('nologchan'); + DXDebug::dbgprintring(5) if DXDebug::isdbg('nologchan'); # DXDebug::dbg(Carp::longmess(\@_)); DXDebug::longmess(\@_); } ); @@ -104,7 +104,7 @@ sub dbgtrace last if $pkg =~ /Mojo/; # say "*** in dbgtrace $i after mojo"; $_isdbg = 'trace'; - dbg("Stack ($i): $pkg::$subr in $fn line: $l"); + dbg("Stack ($i): ${pkg}::$subr in $fn line: $l"); } $_isdbg = ''; } @@ -119,8 +119,8 @@ sub dbg my @l = split /\n/, $r; foreach my $l (@l) { $l =~ s/([\x00-\x08\x0B-\x1f\x7f-\xff])/sprintf("%%%02X",ord($1))/eg; - print "$l\n" if defined \*STDOUT && !$no_stdout; my $tag = $_isdbg ? "($_isdbg) " : '(*) '; + print "$tag$l\n" if defined \*STDOUT && !$no_stdout; my $str = "$t^$tag$l"; &$callback($str) if $callback; if ($dbgringlth) { @@ -135,6 +135,7 @@ sub dbg sub dbginit { + my $basename = shift || 'debug'; $callback = shift; # add sig{__DIE__} handling @@ -161,7 +162,7 @@ sub dbginit } } - $fp = DXLog::new('debug', 'dat', 'd'); + $fp = DXLog::new($basename, 'dat', 'd'); dbgclearring(); } @@ -183,6 +184,7 @@ sub dbgdump my $l = shift; my $m = shift; if ($dbglevel{$l} || $l eq 'err') { + my @out; foreach my $l (@_) { for (my $o = 0; $o < length $l; $o += 16) { my $c = substr $l, $o, 16; @@ -190,11 +192,12 @@ sub dbgdump $c =~ s/[\x00-\x1f\x7f-\xff]/./g; my $left = 16 - length $c; $h .= ' ' x (2 * $left) if $left > 0; - dbg($m . sprintf("%4d:", $o) . "$h $c"); + push @out, $m . sprintf("%4d:", $o) . "$h $c"; $m = ' ' x (length $m); } } - } + dbg(@out) if isdbg($l); # yes, I know, I have my reasons; + } } sub dbgadd @@ -294,6 +297,12 @@ sub dbgclean } } +# force a category for the next (unconditional) dbg message (replace (*) with ()) +sub dbgsetcat +{ + $_isdbg = shift; +} + 1; __END__