Perl Monks, i'm somewhat a of Perl Rookie and i'm looking to write a program where I need to maintain a log file. The program will be farily long, and i'd like to simply be able to call a subroutine with a message and have it timestamp it and output it to the log file. For example:
my $fh = shift;
my $message = shift;
my $timestamp = time;
print $fh $timestamp . ": " . $message . "\n";
I'd like to be able to call log_it from anywhere without having to pass $fh (the filehandle for the logfile) though every subroutine in the entire program just so I can log to that file. I know one solution would be open and close the log file every single time, but that dosn't seem that practical to me (or a very good practice). I realize there a numerous logging modules in CPAN, most of which are overkill for what I want to do, but i'd rather learn the best (object oriented?) method for doing this without using a global filehandle.