X-Git-Url: http://gb7djk.dxcluster.net/gitweb/gitweb.cgi?a=blobdiff_plain;f=perl%2FDXDebug.pm;h=1207492dbb0ec77209edb8816b4d574b95f8177a;hb=68fa2f8ae34d78464cb196851a7ce09ebef61b1b;hp=dbeab595045870a1ee74e360ea5a5af5bf4f9aac;hpb=fd0a34c34ad4112ee21e0730f7307498ff437e18;p=spider.git diff --git a/perl/DXDebug.pm b/perl/DXDebug.pm index dbeab595..1207492d 100644 --- a/perl/DXDebug.pm +++ b/perl/DXDebug.pm @@ -19,6 +19,7 @@ use vars qw(%dbglevel $fp $callback $cleandays $keepdays); use DXUtil; use DXLog (); use Carp (); +use POSIX qw(isatty); %dbglevel = (); $fp = undef; @@ -26,6 +27,8 @@ $callback = undef; $keepdays = 10; $cleandays = 100; +our $no_stdout; # set if not running in a terminal + # Avoid generating "subroutine redefined" warnings with the following # hack (from CGI::Carp): if (!defined $DB::VERSION) { @@ -66,7 +69,7 @@ sub dbg($) my @l = split /\n/, $r; for (@l) { s/([\x00-\x08\x0B-\x1f\x7f-\xff])/uc sprintf("%%%02x",ord($1))/eg; - print "$_\n" if defined \*STDOUT; + print "$_\n" if defined \*STDOUT && !$no_stdout; my $str = "$t^$_"; &$callback($str) if $callback; $fp->writeunix($t, $str); @@ -79,7 +82,7 @@ sub dbginit $callback = shift; # add sig{__DIE__} handling - if (!defined $DB::VERSION) { + unless (defined $DB::VERSION) { $SIG{__WARN__} = sub { if ($_[0] =~ /Deep\s+recursion/i) { dbg($@); @@ -92,6 +95,13 @@ sub dbginit }; $SIG{__DIE__} = sub { dbg($@); dbg(Carp::longmess(@_)); }; + + # switch off STDOUT printing if we are not talking to a TTY + unless ($^O =~ /^MS/ || $^O =~ /^OS-2/) { + unless (isatty(STDOUT->fileno)) { + ++$no_stdout; + } + } } $fp = DXLog::new('debug', 'dat', 'd'); @@ -106,9 +116,11 @@ sub dbgclose sub dbgdump { + return unless $fp; + my $l = shift; my $m = shift; - if ($fp && ($dbglevel{$l} || $l eq 'err')) { + if ($dbglevel{$l} || $l eq 'err') { foreach my $l (@_) { for (my $o = 0; $o < length $l; $o += 16) { my $c = substr $l, $o, 16;