Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

(jcwren) RE: Easy, elemental, but cool debug trick.

by jcwren (Prior)
on May 25, 2000 at 00:06 UTC ( [id://14656]=note: print w/replies, xml ) Need Help??


in reply to Easy, elemental, but cool debug trick.

I use a similiar technique. When debugging a CGI application, however, prints can really mess you up.

For that situation, I have a routine (below) that writes to a file. It accepts two parameters, one which is a class string, and a message string. The section string allows me to put messages in a arbitrary category (say, 'debug', 'authentication', or 'SQL'), and the text to be printed.

Each message is timestamped, and also stamped with a user ID (that's internal to me application, and could be ignored).

I also have a similiar version that use the syslog facility to write /var/log/messages.

sub debug_log { @_ == 2 or confess "Incorrect number of arguments"; my ($section, $action) = @_; my $userid = 0; my $string = 0; $userid = $globalUserID || "<nobody>"; $string = sprintf ("%s %s %s:%s\n", scalar localtime, $userid, $sec +tion, $action); open (SINK, ">> /home/httpd/somedir/logfile") or confess "Can't ope +n logfile"; print SINK $string; close (SINK) or confess "Can't close logfile"; }

Replies are listed 'Best First'.
RE: RE: Easy, elemental, but cool debug trick.
by ask (Pilgrim) on May 25, 2000 at 13:43 UTC
    Just always use warn "foobar" if $DEBUG instead of print, then it will do the right thingtm under both mod_cgi and mod_perl. For logging you should take a look at the Log::Agent module available on CPAN.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (5)
As of 2024-04-19 16:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found