I use (and wrote) a logging framework that is much like you describe. Basically the usage is something like this:

use My::Funky::Logger; # program goes here

The loggers import function dupes and ties STDOUT and STDERR as well as install $SIG{__WARN__} and $SIG{__DIE__} handlers to intercept calls to warn and die even if they are generated by perl. All output via any of these mechanisms is duely logged along with the file, linenumber and procedure where the output originated. Timestamps are provided for each output. A number of utility subs are provided to allow output that bypasses the logging, or vice vers allows logging without actually emitting output. All output is logged to a central directory on the machine using the scripts name as the basis of the logfile name (ie $0).

My thinking was that its easier to modify a script so some part of its output is NOT logged than it is to modify a script to make most of what it outputs logged. Furthermore I tend to think that subroutines like your WriteLog() are a bad call as they are a real pain to retrofit to an existing script, and in my experience a lot of scripts that go into production start off as "little scripts" where such efforts tend to be omitted.

I actually added other cool features, like the logger automatically sends out status emails when the script using it finishes, as well as bindings for using the Win32 eventlog.

Initially i used IO::Tee to do my business, but quickly realized a hand rolled equivelent was easier to deal with.

With luck this gives you enough info to create something similar yourself. :-)

---
demerphq


In reply to Re: Creating a comprehensive log file by demerphq
in thread 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.