Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
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.


In reply to Re: Error reporting from web/mail scripts. by btrott
in thread Error reporting from web/mail scripts. by tomazos

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others making s'mores by the fire in the courtyard of the Monastery: (5)
    As of 2018-12-15 08:41 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      How many stories does it take before you've heard them all?







      Results (69 votes). Check out past polls.

      Notices?