Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re^2: Rambling about debuggers

by DStaal (Chaplain)
on Jul 26, 2011 at 18:38 UTC ( [id://916820]=note: print w/replies, xml ) Need Help??


in reply to Re: Rambling about debuggers
in thread Rambling about debuggers

Mine tend to end up looking like this:

print STDERR "Debug message\n" if $debug > 0;

Where the number may change, giving me several levels of debug statements, and $debug gets set by a command-line accumulating switch. I also tend to leave these in production code: Removing a debug statement is a change in code, and any change in code makes it possible to add a bug, after all.

Replies are listed 'Best First'.
Re^3: Rambling about debuggers
by chrestomanci (Priest) on Jul 27, 2011 at 09:48 UTC

    You can achieve a similar result, but with more flexibility by using Log::Log4perl. In most of my scripts I usually write something like:

    use Log::Log4perl qw(:easy); use Log::Log4perl::Level; Log::Log4perl->easy_init( {'level'=>$DEBUG, 'layout'=>'%m%n'} ); sub doSomething { my $logger = Log::Log4perl->get_logger(); $logger->debug('some message'); }

    As written above, all the logging messages will go to your console, which is the right thing for small scripts that you are actively debugging. Later on you can reduce the log level to $WARN, so that normal debug statements are suppressed, but warnings and errors still appear.

    If your script evolves into something larger or mission critical, then you can take advantage of the expressive grammar available in Log4perl configuration files to have different log levels in different functions, to send logs to files, databases pipes etc, to send you emails on fatal errors, and to change the log level used by a running script, so if it miss behaves in production you can investigate without downtime.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2024-04-19 23:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found