in reply to my homemade solution to logging (module writes to same log file as the script). What do you think?
use My::Logger; open(my $log_fh, '>>', 'blah.log') or die "Couldn't open log file."; My::Logger->set_handle($log_fh); My::Logger->log("Processing..."); ... My::Logger->log("done.");
package My::Logger; my $fh = *STDERR; sub set_handle { my ($class, $new_fh) = @_; $fh = $new_fh; } sub log { my $msg = join('', @_); $msg =~ s/\n+\z/\n/; print $fh $msg; } 1;
You might want to let the module handle opening the file too (passing it a file name).
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: my homemade solution to logging (module writes to same log file as the script). What do you think?
by Anonymous Monk on Feb 25, 2010 at 20:28 UTC |