SPUG: Last night's meeting

Brian Maher maherb at brimworks.com
Sat Mar 20 10:20:16 CST 2004

FYI, if you want to have "permanent breakpoints", simply put this in 
your code where you want it to break:

    $DB::single = 1;

When not ran under the debugger, nothing happens, but with the debugger 
on, it is like having a breakpoint.  Please also note that perl will 
give you a warning unless you put 'package DB; our $single;' at the top 
of your source file before your package declaration.

Of course print statements can be very handy.  I've always thought of 
implementing the following two perl modules that would help with 
debugging (please note that the name Log4Perl is mis-leading, this is 
different from Log::Log4perl which is available on CPAN):

    package My::Module;

    use strict;
    use Log4Perl;
    use Time::HiRes qw(gettimeofday);

    my $LOG = Log4Perl->getRecorder(__PACKAGE__);

    sub my_sub {
       $LOG->warn("Couldn't find environment variable FOO, defaulting to 
       $LOG->fatal("Couldn't find necessary config file!");

       my $time = [gettimeofday];
       ... Do select query ...
       $LOG->performance("SQL:Select * from foo", $time);

By default, warn() and fatal() calls are written to STDERR, and all 
other calls are ignored.  The interesting part is the fact that you can 
configure exactly what debug statements get printed based on the 
package/subroutine that the warn()/debug()/fatal()/performance() was 
called from (using perl's handy caller() builtin function).  Here is 
the basic object model:

      This is returned from Log4Perl->getRecorder("Package::Name").  
This class is responsible for routing the various debug messages to all 
registered loggers.  If no loggers are registered, all warn/fatal 
messages are printed to STDERR using the same format as the builtin 
warn() function (appends at $file line $lineno).

        performance($category, $startTime)


      Anyone can implement this interface that consists of one method:

      log($self,  $msgOrCategory, $deltaTimeFloatingPointSeconds, 

I would imagine that some default Loggers would be implemented in this 
framework that would allow you to do such things as print log messages 
at the bottom of a webpage served with mod_perl, or print out a timings 
log file so you can monitor your servers performance, tweak the 
verbosity of individual packages (so you can debug just your module) 

That is my 2 cents.

On Friday, March 19, 2004, at 12:01  AM, Michael R. Wolf wrote:

> "Marc M. Adkins" <Perl at doorways.org> writes:
> [...]
>> And yet...I hesitate sometimes to mention it in 'polite' company 
>> because
> We're not *that* 'polite' -- I prefer to think we're respectfully
> courteous, yet not quite tame -- but thanks for the compliment. :-)
> [...]
>>  humble print statement.
> The debugger of infinate power?
> -- 
> Michael R. Wolf
>     All mammals learn by playing!
>         MichaelRWolf at att.net
> _____________________________________________________________
> Seattle Perl Users Group Mailing List
> POST TO: spug-list at mail.pm.org  http://spugwiki.perlocity.org
> ACCOUNT CONFIG: http://mail.pm.org/mailman/listinfo/spug-list
> MEETINGS: 3rd Tuesdays, Location Unknown
> WEB PAGE: http://www.seattleperl.org
Brian Maher >> Glory to God <<

More information about the spug-list mailing list