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. :-)
In reply to Re: Creating a comprehensive log file
by demerphq
in thread Creating a comprehensive log file
by juo
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |