First, have you tried using the "%attrib" part of the DBI "connect()" call? It can be used to set parameters like "PrintError" and "RaiseError", which might help to control the reporting behavior in the way that you want.

Second, if you have access to a bash or bourne shell, you could just redirect STDERR to a file at the command line, like this:

your_script [options and args] 2> errlog
(There is a Windows port of bash, if you happen to be on a Windows system.)

Finally, if neither of the above points will work for you, try this at the beginning of your script:

open( STDERR, ">>$debug_output" ) or die "Can't write errlog: $!\n";
That way, you don't need any special functions or special DBI connect args -- everything that Perl would normally print to STDERR will be stored in the file whose name is provided in "$debug_output". (The original STDERR handle will be closed, so no error messages will go to the console.)

In reply to Re: Capturing Error message in a log file. by graff
in thread Capturing Error message in a log file. by Ananda

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.