Logging to a file

Using search.cpan.org there are many options to logging to a file.  Finding just one that does exactly what you need can be a challenge.

Here, I will talk just about one:  Log::LogLite

LogLite was almost exactly what I was looking for, but I found it to be lacking in one area:  The date output formatting was most useless, and not customizable. "YYYY-DD-MM"!?  Why not YYYY-MM-DD like most computer programmers like, since it alpha sorts correctly?

A simple change near line 69 like so:

my $line = $self->{TEMPLATE};
  $line =~ s!<date>!$self->date_string()!igoe;
  # changed to $self->date_string() so module can be customized by deriving from.

And now I can derive modules from Log::LogLite and customize the date formatting.

package MyLog;
use Log::LogLite;
 
@ISA = ("Log::LogLite");
 
sub date_string {
 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
 return sprintf( "%02d/%02d/%04d %02d:%02d:%02d",
  $mon + 1, $mday, $year + 1900, $hour, $min, $sec );
} # of date_string

But since I have to modify the original module in order to have the flexibility to customize it, I just renamed the module LogLite.pm to MyLog.pm, made the above two changes and copy it around to where I need it. 

So much for code reuse.