in reply to Re^3: Logging to web page with Mojolicious and strict
in thread Logging to web page with Mojolicious and strict

Updated code:
package Logger; use warnings; use strict; use Mojo::Log; sub new { my $class = shift; my $self = {LogLine => '', appLog => Mojo::Log->new( path => './lo +gs/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, $DayOf +Year, $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;
I decided to create a Mojo::Log object within my Logger class -- because I still want every call to Logger::add() to write to the Mojo log file as well. Creating a new instance of Mojo::Log inside the class seemed to work better than creating it in the main app and passing it in. Thanks again bliako for your suggestions.