Re: What module do you like for debugging CGI scripts
by jettero (Monsignor) on Jan 27, 2007 at 12:28 UTC
|
I usually use CGI::Carp qw(fatalsToBrowser) to trap errors so I can see them. I use sudo tail -f /var/log/http-errors.log to watch for my warnings. If there's something better, I'd like to know about it also.
| [reply] |
|
|
I took a look at CGI::Carp and it does not support the ability to specify the level of log msg that you want output. I also don't see a way to switch off logging altogether when in a production environment.
| [reply] |
|
|
You don't want to turn off the logging altogether in a production environment, merely not to send the output to the browser. CGI::Carp will, by default, send the output to stderr, hence to the server log, which you do want in a production environment.
The following snippet should help:
BEGIN {
my $carp_arg;
if ($ENV{ENV} =~ /DEV/) { # or some other test for a non producti
+on env
$carp_arg = 'fatalsToBrowser';
}
use CGI::Carp $carp_arg;
}
--
Oh Lord, won’t you burn me a Knoppix CD ?
My friends all rate Windows, I must disagree.
Your powers of persuasion will set them all free,
So oh Lord, won’t you burn me a Knoppix CD ? (Missquoting Janis Joplin)
| [reply] [d/l] |
|
|
Surely there are no bugs in the code you're running on your production environment ;)
Also, if you have if $DEBUG attached to the end of all your calls to warn then they'll just disappear when you set $DEBUG=undef
@_=qw; ask f00li5h to appear and remain for a moment of pretend better than a lifetime;;s;;@_[map hex,split'',B204316D8C2A4516DE];;y/05/os/&print;
| [reply] [d/l] [select] |
|
|
| [reply] |
Re: What module do you like for debugging CGI scripts
by merlyn (Sage) on Jan 27, 2007 at 13:46 UTC
|
| [reply] |
Re: What module do you like for debugging CGI scripts - Log::Dispatch
by imp (Priest) on Jan 27, 2007 at 15:28 UTC
|
My preferred approach is to only log fairly important events by default, but to record the entire debug trail in a database when an error occurs. In production environments this approach avoids the usual problem of having either too much log output (filling the log file and wasting disk IO), or too little (unable to diagnose errors). It is also helpful to log the contents of %ENV and sometimes a dump of the current CGI params, but be careful not to record credit card numbers in a log file.
The best module for this that I have found is Log::Dispatch with Log::Dispatch::Buffer, but I'm sure you could do something similar with Log::Log4perl. You should always log things of notice level or higher to syslog in my opinion.
I designed this sytem for something that used CGI::Application and added a teardown task that handled the check for highest severity.
If your reason for asking for a logging system recommendation is that you are currently trying to track down a bug, then I very strongly recommend you break some of your supporting code into supporting modules and write a reasonable test suite for it. Once you start writing tests you'll never go back :)
| [reply] |
Re: What module do you like for debugging CGI scripts
by SFLEX (Chaplain) on Jan 27, 2007 at 13:28 UTC
|
I have found this to be a realy good error log for Perl.
use strict;
use warnings;
# Log Perl Warnings and Errors - Standard
# may have to make the blank file "error.log".
use CGI::Carp qw(carpout);
open(LOG, '>>', './error.log')
or die "Unable to append to at $!\n";
carpout(*LOG);
This should log all warnings errors.
Works the best when use strict and use warnings are used. | [reply] [d/l] |
Re: What module do you like for debugging CGI scripts
by talexb (Chancellor) on Jan 28, 2007 at 01:01 UTC
|
Someone's already mentioned Log::Log4perl, but let me just add another vote. I use it in Production code, and if Something Goes Bad, instead of hacking code on a Production server (never a good idea), I can just turn up the debug level from WARN to DEBUG and watch a few web requests go by in the log file.
There are also lots of options .. for example, instead of sending messages to a log file, they can be E-Mailed, sent out a serial port for external logging, etc., etc.
Highly recommended.
Alex / talexb / Toronto
"Groklaw is the open-source mentality applied to legal research" ~ Linus Torvalds
| [reply] |
Re: What module do you like for debugging CGI scripts
by logie17 (Friar) on Jan 27, 2007 at 18:47 UTC
|
| [reply] |
Re: What module do you like for debugging CGI scripts
by jimX11 (Friar) on Jan 28, 2007 at 02:52 UTC
|
| [reply] |
Re: What module do you like for debugging CGI scripts
by EvanK (Chaplain) on Jan 28, 2007 at 08:26 UTC
|
personally, I use a combination of CGI::Carp and Data::Dumper. its quite handy to not have to tail the (usually) giant apache error logs every time i test a new script. as with any method that I prefer, your mileage may vary :)
__________ The trouble with having an open mind, of course, is that people will insist on coming along and trying to put things in it.
- Terry Pratchett
| [reply] |
Re: What module do you like for debugging CGI scripts
by hesco (Deacon) on Jan 28, 2007 at 08:31 UTC
|
| [reply] |
Re: What module do you like for debugging CGI scripts
by uwevoelker (Pilgrim) on Jan 28, 2007 at 12:43 UTC
|
I use Devel::ptkdb (Tk debugger). It works for CGI, command line and even Catalyst applications. In case of Catalyst you have to load some modules by hand (e. g. the controller) with
perl -d:ptkdb -MMyApp::Controller::Root script/myapp_server_debug.pl
| [reply] [d/l] |