Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Determining debug levels

by mirod (Canon)
on Feb 28, 2002 at 08:53 UTC ( [id://148160]=note: print w/replies, xml ) Need Help??


in reply to Determining debug levels

I have recently started to use a different technique: all the Perl files in my application start with something like:

my %trace=( index_generation => 1, link_computation => 0, link output => 1, );

and the log statements read like:

print LOG "blah" if( $trace{link_outpout});

When I see a problem in the result (I am doing mostly batch processing here, so YMMV) I can then turn on whatever trace is needed. I find this very convenient, it allows me to focus on whatever area the problem seems to be in.

Of course this could be improved by adding all and none fields to the trace hash, so I could write:

print LOG "blah" if( $trace{all} or ($trace{link_outpout} and !$trace{none}));

Or even better, write a function my_log:

sub my_log { my $type= shift; print LOG @_ if( ( $trace{all} or ( $trace{link_outpout} and !$trace{none} ) ); }

I find this more flexible than just a numeric value, that inevitably ends up filling my log files with garbage. I guess just prefixing the log entry with the type of log and greping it could also work, but I like this way better because I can also use it when I am in debug mode under perl -d.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://148160]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (9)
As of 2024-04-18 20:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found