Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Error reporting from web/mail scripts.

by tomazos (Deacon)
on Aug 26, 2001 at 21:44 UTC ( [id://107959]=perlquestion: print w/replies, xml ) Need Help??

tomazos has asked for the wisdom of the Perl Monks concerning the following question:

When you put a web CGI script or an email processing script or a cron-run script into production, you can't use the standard die and warn functions to get errors because the standard error stream goes to some random place.

I have heard mention of ways to do things with some other functions called carp, croak and something else. Could someone firstly explain what these functions are and what module I can find them in?

Secondly, how can these be hooked up with automatically run scripts (such as web, mail and cron) such that if an error occurs it will send me an email containing the script name, line number and nature of the error that occured?

Replies are listed 'Best First'.
Re: Error reporting from web/mail scripts.
by btrott (Parson) on Aug 26, 2001 at 22:28 UTC
    You say:
    > When you put a web CGI script or an email processing > script or a cron-run script into production, you can't use > the standard die and warn functions to get errors because > the standard error stream goes to some random place.
    No, it goes to the webserver error log. I wouldn't call it a random place, necessarily. :) In my opinion, that's where it *should* go; in a production system it certainly shouldn't be sent to the browser, because that could reveal sensitive information and introduce a security hole.

    carp and croak aren't really going to help you here. They write to STDERR just like die and warn do. The difference is that they report errors from the perspective of the caller.

    You *can*, however, use CGI::Carp. This lets you use a carpout function to write error messages to a different filehandle than STDERR. From the docs:

    BEGIN { use CGI::Carp qw(carpout); open(LOG, ">>/usr/local/cgi-logs/mycgi-log") or die("Unable to open mycgi-log: $!\n"); carpout(LOG); }
    However, the docs do say that using carpout is a hit on performance, so it is recommended for development usage only.

    If you would like to capture errors and have them sent as email messages to you, you could use a $SIG{__DIE__} handler, or you could wrap your script in an eval to catch errors; if an error occurs, send yourself email with the error message.

Re: Error reporting from web/mail scripts.
by little (Curate) on Aug 26, 2001 at 22:15 UTC
    use CGI::Carp;
    look up the docs shipping with your perl installation as CGI.pm is a standard module and comes along with CGI::Carp;

    Have a nice day
    All decision is left to your taste
    Update
    But you could also:
    use CGI::Debug;
Re: Error reporting from web/mail scripts.
by echo (Pilgrim) on Aug 26, 2001 at 22:58 UTC
    Cron job STDERR doesn't go to a random place either, on most modern Unix-like systems it is mailed to the user running the cronjob. You can change the recipient by prepending this line to your crontab file:
    MAILTO=foo@example.com

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2024-04-19 21:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found