our @EXPORT_OK = qw(New Log GetLogLevels);
use Sys::Syslog qw(:DEFAULT setlogsock);
+use POSIX qw(strftime);
# Hash which stores all supported log levels and their priority.
my %loglevels = (
my $self = shift;
my ($type, $message) = @_;
+ # Get current date and time and format like: "Jan 01 00:00:01"
+ my $now = strftime "%b %e %H:%M:%S", localtime();
+
# Print message on STDOUT.
- print STDOUT "\[$type\] $message\n";
+ print STDOUT "$now \[$type\] $message\n";
}
#
my $self = shift;
my ($type, $message) = @_;
+ # Get current date and time and format like: "Jan 01 00:00:01"
+ my $now = strftime "%b %e %H:%M:%S", localtime();
+
# Open the logfile for writing.
open(LOGFILE, '>>', $self->{LogFile}) or die "Could not write to $self->{LogFile}: $!\n";
# Write log message to file.
- print LOGFILE "\[$type\] $message\n";
+ print LOGFILE "$now \[$type\] $message\n";
# Close filehandle.
close(FILE);