Author: spadkins
Date: Fri Jun 22 14:00:38 2007
New Revision: 9669

Modified:
   p5ee/trunk/App-Context/lib/App.pm
   p5ee/trunk/App-Context/lib/App/Context.pm

Log:
add support for the --debug_file option which redirects the output for --trace, 
--debug, --debug_sql, etc.

Modified: p5ee/trunk/App-Context/lib/App.pm
==============================================================================
--- p5ee/trunk/App-Context/lib/App.pm   (original)
+++ p5ee/trunk/App-Context/lib/App.pm   Fri Jun 22 14:00:38 2007
@@ -267,7 +267,6 @@
     $App::scope_exclusive = 0;
     $App::trace = 0;
     $App::DEBUG = 0;
-    $App::DEBUG_FILE = "";
 }
 
 #################################################################
@@ -330,10 +329,26 @@
 
     my $debug_file = $App::options{debug_file};
     if ($debug_file) {
-        if ($debug_file !~ /^[>|]/) {
-            $debug_file = ">> $debug_file";
+        if ($debug_file eq "STDOUT") {
+            $App::DEBUG_FILE = \*STDOUT;
         }
-        open(App::DEBUG_FILE, $debug_file);
+        elsif ($debug_file eq "STDERR") {
+            $App::DEBUG_FILE = \*STDERR;
+        }
+        else {
+            if ($debug_file !~ /^[>|]/) {
+                $debug_file = "> $debug_file";
+            }
+            if (open(App::DEBUG_FILE_HANDLE, $debug_file)) {
+                $App::DEBUG_FILE = \*App::DEBUG_FILE_HANDLE;
+            }
+            else {
+                warn "WARNING: Couldn't open $debug_file: $!\n";
+            }
+        }
+    }
+    else {
+        $App::DEBUG_FILE = \*STDOUT;
     }
 }
 
@@ -864,19 +879,19 @@
             if ($text_len + $trailer_len > $App::trace_width) {
                 my $len = $App::trace_width - $trailer_len;
                 $len = 1 if ($len < 1);
-                print substr($text, 0, $len), $trailer, "\n";
+                print $App::DEBUG_FILE substr($text, 0, $len), $trailer, "\n";
             }
             elsif ($App::trace_justify) {
                 my $len = $App::trace_width - $trailer_len - $text_len;
                 $len = 0 if ($len < 0);  # should never happen
-                print $text, ("." x $len), $trailer, "\n";
+                print $App::DEBUG_FILE $text, ("." x $len), $trailer, "\n";
             }
             else {
-                print $text, $trailer, "\n";
+                print $App::DEBUG_FILE $text, $trailer, "\n";
             }
         }
         else {
-            print $text, $trailer, "\n";
+            print $App::DEBUG_FILE $text, $trailer, "\n";
         }
         $calldepth++;
     }
@@ -940,10 +955,10 @@
         }
         $text =~ s/\n/\\n/g;
         if ($App::trace_width && length($text) > $App::trace_width) {
-            print substr($text, 0, $App::trace_width), "\n";
+            print $App::DEBUG_FILE substr($text, 0, $App::trace_width), "\n";
         }
         else {
-            print $text, "\n";
+            print $App::DEBUG_FILE $text, "\n";
         }
     }
     return(@_);

Modified: p5ee/trunk/App-Context/lib/App/Context.pm
==============================================================================
--- p5ee/trunk/App-Context/lib/App/Context.pm   (original)
+++ p5ee/trunk/App-Context/lib/App/Context.pm   Fri Jun 22 14:00:38 2007
@@ -1766,8 +1766,8 @@
 
 sub dbgprint {
     my $self = shift;
-    if (defined $App::options{debugfile}) {
-        print App::DEBUGFILE $$, ": ", @_, "\n";
+    if (defined $App::options{debug_file}) {
+        print $App::DEBUG_FILE $$, ": ", @_, "\n";
     }
     else {
         print STDERR "Debug: ", @_, "\n";

Reply via email to