package Logger; use warnings; use strict; use Mojo::Log; sub new { my $class = shift; my $self = {LogLine => '', appLog => Mojo::Log->new( path => './logs/mojo-log', level => 'debug' )}; bless $self, $class; return $self; } sub add { my ( $self, $LogItem ) = @_; my $time = FormatDate(); $self->{LogLine} .= "[ $time ] :: $LogItem\n" if defined($LogItem); $self->{appLog}->debug($LogItem); } sub get { my( $self ) = @_; return $self->{LogLine}; } sub clear { my( $self ) = @_; $self->{LogLine} = ''; } sub FormatDate { my $Offset = shift; # number of seconds to offset the current time. Example: FormatDate(3600) returns the time one hour from now. $Offset = 0 unless ($Offset); my ($Second, $Minute, $Hour, $Day, $Month, $Year, $WeekDay, $DayOfYear, $IsDST) = localtime(time+$Offset); $Year = $Year + 1900; $Month = $Month + 1; $Day = sprintf ("%02s", $Day); $Month = sprintf ("%02s", $Month); $Hour = sprintf ("%02s", $Hour); $Minute = sprintf ("%02s", $Minute); $Second = sprintf ("%02s", $Second); return "$Year-$Month-$Day $Hour:$Minute:$Second"; } 1;