#!/usr/bin/perl # # Logg.pm # # package MyLib::Logger; use strict; use warnings; use base 'Exporter'; our @EXPORT_OK = qw( data_log ); # Exported, if explicitly requested our $VERSION = '0.01'; sub data_log { my ($log_file, @data) = @_; my $log_fh; # Log data to file my $timestamp = '[' . localtime() . '] '; if ($log_file && ($log_file !~ /^STDOUT$/i)) { # Allow tee-ing of logfile to STDOUT and a file ('|tee -a log_file.txt') if ($log_file !~ /^\|/) { $log_file = ">>${log_file}"; } open $log_fh, $log_file or warn "Can't open $log_file: $!"; print $log_fh $timestamp, @data, "\n"; close $log_fh; } else { print $timestamp, @data, "\n"; } return; } 1; # End of Logg.pm