Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > How to deal with Debug information in a large program.

Reply
Thread Tools

How to deal with Debug information in a large program.

 
 
Franklin Lee
Guest
Posts: n/a
 
      07-01-2003
Hi All,

I'm in trouble with Debug information in a large program.
Some info I just want to print in degug phase.
Now I do as follow:
################################################## #########
....
use vars qw($Debug);
$Debug ||= 0;

....
#Define option -D
$Debug=1 if(defined($opt{'D'});

....
#Print Debug info when necessary
if($Debug) {
print("Debugxxxxx\n");
}
################################################## ##########

Do you think it's a good way to deal with Debug info.
Or do you have a better way to deal with it?

Any suggestions are welcome!

Thank you!

Franklin


 
Reply With Quote
 
 
 
 
Rich
Guest
Posts: n/a
 
      07-01-2003
Franklin Lee wrote:

> Hi All,
>
> I'm in trouble with Debug information in a large program.
> Some info I just want to print in degug phase.
> Now I do as follow:
> ################################################## #########
> ...
> use vars qw($Debug);
> $Debug ||= 0;
>
> ...
> #Define option -D
> $Debug=1 if(defined($opt{'D'});
>
> ...
> #Print Debug info when necessary
> if($Debug) {
> print("Debugxxxxx\n");
> }
> ################################################## ##########
>
> Do you think it's a good way to deal with Debug info.
> Or do you have a better way to deal with it?
>
> Any suggestions are welcome!


This will make your life hell in the long run, because it's an all or
nothing approach. As your codebase grows, you'll have more and more
debugging messages - many of which will be useless when you're trying to
debug specific problems.

Look at Log::Log4perl:

"Logging beats a debugger if you want to know what's going on in your code
during runtime. However, traditional logging packages are too static and
generate a flood of log messages in your log files that won't help you.

Log::Log4perl is different. It allows you to control the amount of logging
messages generated at three different levels:

At a central location in your system (either in a configuration file or in
the startup code) you specify which components (classes, functions) of your
system should generate logs.

You specify how detailed the logging of these components should be by
specifying logging levels.

You also specify which so-called appenders you want to feed your log
messages to ("Print it to the screen and also append it to /tmp/my.log")
and which format ("Write the date first, then the file name and line
number, and then the log message") they should be in.

This is a very powerful and flexible mechanism. You can turn on and off your
logs at any time, specify the level of detail and make that dependent on
the subsystem that's currently executed."


So, in my code I have lines such as:

Log::Log4perl->get_logger(__PACKAGE__)->debug
("conditionally creating home directory: $home") if DEBUG;

In my debug module (heavily edited):

our @EXPORT_OK = qw( DEBUG );

BEGIN
{
if ( $ENV{RIDAS_DEBUG} )
{
*DEBUG = sub () {1};
}
else
{
*DEBUG = sub () {0};
}
}

This now gives me control of the amount of debugging info emitted on a
module by module basis, specified by a simple Log4perl configuration file.

Having the "if DEBUG" conditional allows debugging calls to be optimized
away at compile time when not required, so performance does not suffer.

Sure, this seems like a hastle to begin with, and the Log::Log4perl docs are
heavy in places, but its a well designed framework, based off the widely
used and respected Java log4j project.

That's my suggestion anyway - it's worked very well for me, but others are
sure to have equally good ways of doing things

Cheers,
--
Rich
http://www.velocityreviews.com/forums/(E-Mail Removed)
 
Reply With Quote
 
 
 
 
Bob Walton
Guest
Posts: n/a
 
      07-01-2003
Franklin Lee wrote:

> Hi All,
>
> I'm in trouble with Debug information in a large program.
> Some info I just want to print in degug phase.
> Now I do as follow:
> ################################################## #########
> ...
> use vars qw($Debug);
> $Debug ||= 0;
>
> ...
> #Define option -D
> $Debug=1 if(defined($opt{'D'});
>
> ...
> #Print Debug info when necessary
> if($Debug) {
> print("Debugxxxxx\n");
> }
> ################################################## ##########
>
> Do you think it's a good way to deal with Debug info.
> Or do you have a better way to deal with it?
>
> Any suggestions are welcome!

....
> Franklin


Another possible approach is:

use Filter::Simple;

to make a source code filter which will include or exclude debug
statements, which would be statements that start with a flag like
perhaps "#db ". The filter would simply remove the "#db " if debugging
is desired; otherwise, those statements would just be commentary, and
wouldn't normally be compiled or executed -- and you don't have to do
the clumsy if($Debug){...} bit. One could get fancy and include debug
levels with stuff like #db1 , #db2 , etc.

--
Bob Walton

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
AMD64 or Semperon, deal or no deal? Tad Confused Computer Information 7 04-13-2006 05:43 PM
Config Mgr Debug/Release and Web.config Compilation debug=true RonL ASP .Net 0 04-08-2006 03:50 PM
deal or no deal rbt Python 7 12-28-2005 08:57 PM
Debug (DLL MFC) -> Debug (Static MFC) ringos75 C++ 0 04-14-2005 01:50 PM



Advertisments