X-Git-Url: http://gb7djk.dxcluster.net/gitweb/gitweb.cgi?a=blobdiff_plain;f=perl%2FDXDebug.pm;fp=perl%2FDXDebug.pm;h=5bf2470dbf8526282902c7592eab9234654f4ade;hb=a9bc2c5a87691ca5bed6e408c5908695bd65387a;hp=dbeab595045870a1ee74e360ea5a5af5bf4f9aac;hpb=9704e8d29489c2db3a0051f58ea1e40e76b7f843;p=spider.git diff --git a/perl/DXDebug.pm b/perl/DXDebug.pm index dbeab595..5bf2470d 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');