Hello,

I wonder if anybody had any good suggestions to create a comphrehensive log file when running scripts. The log file should contain printed lines send to it but also contain all the warnings and errors from the STDOUT. Is their a good way to do this besides from re-directing my STDOUT in the beginning of a script direclty to a filehandle.

open STDOUT ">whatever.dat"; # Here comes all the coding close STDOUT;

I don't want to remove my STDOUT, I just want in parallel capture it in a log file.

The result could be something like this

PRINT INFO 12December2004 "Importing JOB x into database" PRINT WARNING 12December2004 "Job did already exist" STDOUT ERROR 12December2004 "No permission to overwrite job"

So instead of having all the time an open filehandle is their another way to just capture when something goes to the STDOUT and then write this into a file. For the print I think I can do this easily with the following subroutine but I don't have an idea to also re-direct STDOUT errors and warnings to that routine

sub WriteLog { my ($script,$type,$log) = @_; $logfile = $job_path.'/user/LogFile.txt'; open (LOG, "$logfile") || die "File does not exist\n"; print "$script\t$type\t$today\t$log\n"; close (LOG); }

In reply to Creating a comprehensive log file by juo

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.