I am writing a new type of logger. If the main program dies anywhere along the way, I would like to be able to capture the dying message, the class will already write to log on death, but it will not write the die <message>. Any one out there ever try this? I have tried $!, $^W, and $@, but none of these report the die message.
#The logger will write to the file when the logger is #destroyed, or by explicitly calling the flush() function. my $l = Loger->new(fileName=>'/tmp/log.log'); $l->add("Log line 1","cat to log"); die "Died for some reason..."; #More program below
I would like the log to read: timestamp::Log line 1::cat to log timestamp::Died for some reason

In reply to Capturing Text from a die command by or10n

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, details, 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, summary, 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.