X-Git-Url: http://dxcluster.net/gitweb/gitweb.cgi?a=blobdiff_plain;f=perl%2FDXDebug.pm;h=3ab7c77084693ec3ff41bbfae672a800fba90ddb;hb=f43ac25669a7b9368d9537eed2043a864a906303;hp=28ae8fe56281137a056bac41954fa6013c1f8481;hpb=ed4c2b52bead2215f39de1d75bc3d09daa83caa9;p=spider.git diff --git a/perl/DXDebug.pm b/perl/DXDebug.pm index 28ae8fe5..3ab7c770 100644 --- a/perl/DXDebug.pm +++ b/perl/DXDebug.pm @@ -25,10 +25,11 @@ package DXDebug; use 5.10.1; +use warnings; 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 +70,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 +105,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 +120,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) { @@ -130,10 +131,12 @@ sub dbg $fp->writeunix($t, $str) unless !$fp || $dbglevel{"nolog$_isdbg"} ; } } + $_isdbg = ''; } sub dbginit { + my $basename = shift || 'debug'; $callback = shift; # add sig{__DIE__} handling @@ -160,7 +163,7 @@ sub dbginit } } - $fp = DXLog::new('debug', 'dat', 'd'); + $fp = DXLog::new($basename, 'dat', 'd'); dbgclearring(); } @@ -182,6 +185,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; @@ -189,11 +193,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 @@ -293,6 +298,12 @@ sub dbgclean } } +# force a category for the next (unconditional) dbg message (replace (*) with ()) +sub dbgsetcat +{ + $_isdbg = shift; +} + 1; __END__