X-Git-Url: http://dxcluster.org/gitweb/gitweb.cgi?a=blobdiff_plain;f=perl%2FDXDebug.pm;h=b55d01fcf5ea8de4fa060321e12195468274d8cc;hb=4a89177a94f3a5ca3f3a1d1231ae5cdd6abd5155;hp=a1c63407f71f1b2aba38c58782dbe77f0a73e63b;hpb=8e45a3dac2e136dc0c9d6f1e78f8c048a8d7ba21;p=spider.git diff --git a/perl/DXDebug.pm b/perl/DXDebug.pm index a1c63407..b55d01fc 100644 --- a/perl/DXDebug.pm +++ b/perl/DXDebug.pm @@ -21,7 +21,7 @@ use DXLog (); use Carp qw(cluck); %dbglevel = (); -$fp = DXLog::new('debug', 'dat', 'd'); +$fp = undef; # Avoid generating "subroutine redefined" warnings with the following # hack (from CGI::Carp): @@ -56,6 +56,8 @@ sub _store chomp; my @l = split /\n/; for (@l) { + my $l = $_; + $l =~ s/([\x00\x08\x0B-\x1f\x7f-\xff])/uc sprintf("%%%02x",ord($1))/eg; print "$_\n" if defined \*STDOUT; $fp->writeunix($t, "$t^$_"); } @@ -69,18 +71,21 @@ sub dbginit $SIG{__WARN__} = sub { _store($@, Carp::shortmess(@_)); }; $SIG{__DIE__} = sub { _store($@, Carp::longmess(@_)); }; } + + $fp = DXLog::new('debug', 'dat', 'd'); } sub dbgclose { $SIG{__DIE__} = $SIG{__WARN__} = 'DEFAULT'; - $fp->close(); + $fp->close() if $fp; + undef $fp; } sub dbg { my $l = shift; - if ($dbglevel{$l} || $l eq 'err') { + if ($fp && ($dbglevel{$l} || $l eq 'err')) { my @in = @_; my $t = time; for (@in) {