[Bio] / FigKernelPackages / Tracer.pm Repository:
ViewVC logotype

Diff of /FigKernelPackages/Tracer.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.6, Mon Mar 7 02:01:51 2005 UTC revision 1.8, Wed Apr 6 00:11:50 2005 UTC
# Line 7  Line 7 
7          use strict;          use strict;
8          use Carp qw(longmess croak);          use Carp qw(longmess croak);
9          use CGI;          use CGI;
10            use FIG_Config;
11    
12    my $UsePageBuilder=1;
13    eval {
14     require PageBuilder;
15    };
16    undef $UsePageBuilder if ($@);
17    
18  =head1 Tracing and Debugging Helpers  =head1 Tracing and Debugging Helpers
19    
# Line 42  Line 49 
49    
50  C<< TSetup('3 errors Sprout ERDB', 'HTML'); >>  C<< TSetup('3 errors Sprout ERDB', 'HTML'); >>
51    
52  sets the trace level to 3, activated the C<errors>, C<Sprout>, and C<ERDB> categories, and  sets the trace level to 3, activates the C<errors>, C<Sprout>, and C<ERDB> categories, and
53  specifies that messages should be output as HTML paragraphs. The idea is to make it easier to  specifies that messages should be output as HTML paragraphs. The parameters are formatted
54  input tracing configuration on a web form.  to make it easier to input tracing configuration on a web form.
55    
56  In addition to HTML and file output for trace messages, you can specify that the trace messages  In addition to HTML and file output for trace messages, you can specify that the trace messages
57  be queued. The messages can then be retrieved by calling the L</QTrace> method. This approach  be queued. The messages can then be retrieved by calling the L</QTrace> method. This approach
# Line 69  Line 76 
76  my $TraceLevel = 0;                     # trace level; a higher trace level produces more  my $TraceLevel = 0;                     # trace level; a higher trace level produces more
77                                                          # messages                                                          # messages
78  my @Queue = ();                         # queued list of trace messages.  my @Queue = ();                         # queued list of trace messages.
79    my $LastCategory = "main";  # name of the last category interrogated
80    
81  =head2 Public Methods  =head2 Public Methods
82    
# Line 371  Line 379 
379          # Get the timestamp.          # Get the timestamp.
380          my $timeStamp = Now();          my $timeStamp = Now();
381          # Format the message.          # Format the message.
382          my $formatted = "$timeStamp $message";          my $formatted = "$timeStamp <$LastCategory>: $message";
383          # Process according to the destination.          # Process according to the destination.
384          if ($Destination eq "TEXT") {          if ($Destination eq "TEXT") {
385                  # Write the message to the standard output.                  # Write the message to the standard output.
# Line 445  Line 453 
453                                  $category = $package;                                  $category = $package;
454                          }                          }
455                  }                  }
456                  # Use the package and tracelevel to compute the result.          # Save the category name.
457            $LastCategory = $category;
458                    # Use the category and tracelevel to compute the result.
459                  $retVal = ($traceLevel <= $TraceLevel && exists $Categories{$category});                  $retVal = ($traceLevel <= $TraceLevel && exists $Categories{$category});
460      }      }
461          # Return the computed result.          # Return the computed result.
# Line 958  Line 968 
968      }      }
969  }  }
970    
971    =head3 DebugMode
972    
973    C<< if (Tracer::DebugMode) { ...code... } >>
974    
975    Return TRUE if debug mode has been turned on in FIG_Config, else output
976    an error page and return FALSE.
977    
978    Certain CGI scripts are too dangerous to exist in the production
979    environment. This method provides a simple way to prevent them
980    from working unless they are explicitly turned on in the configuration
981    file by setting C<$FIG_Config::debug_mode> to 1. If debugging mode
982    is not turned on, an error web page will be output.
983    
984    =cut
985    
986    sub DebugMode {
987            # Declare the return variable.
988            my $retVal;
989            # Check the debug configuration.
990            if ($FIG_Config::debug_mode) {
991                    $retVal = 1;
992            } else {
993                    # Here debug mode is off, so we generate an error page.
994                    # RAE: PageBuilder is not part of the standard distro, and broke my machine
995                    if ($UsePageBuilder)
996                    {
997                      my $pageString = PageBuilder::Build(">Html/ErrorPage.html", {}, "Html");
998                      print $pageString;
999                    }
1000                    else
1001                    {
1002                      print STDERR "There was an error here in FiGKernelPackages/Tracer.pm\n";
1003                    }
1004    
1005            }
1006            # Return the determination indicator.
1007            return $retVal;
1008    }
1009    
1010  1;  1;

Legend:
Removed from v.1.6  
changed lines
  Added in v.1.8

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3