Output Logging Routine

This code will allow logging into a file and optionally, to the screen as well. This will create the file if necessary.


sub mlog {
    my ($msg) = @_;
    open (FH, ">> /tmp/logfile.log")
        or croak "error opening logfile: $!n";

    my $timestamp = localtime;
    print FH "$timestamp: $msgn";
    close FH;

    print "$timestamp: $msgn";    # also log to the screen
}

And to use this in your code:


mlog("This is a test log");

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.