euchre-live

Euchre web-app for the socially distant family
git clone git://git.alexkarle.com/euchre-live.git
Log | Files | Refs | README | LICENSE

commit 97b41cd38bf92fd09d3da6cf4c4fbab852fc4a25 (patch)
parent 2fbfd28f3a13773d05cf791231427625385bded9
Author: Alex Karle <alex@karle.co>
Date:   Tue, 12 May 2020 23:45:54 -0400

Euchre::Host: Change print's to proper logging

Mojo::Log is a simple, timestamped, logger. This commit updates the
"print" statements to use a Mojo::Log object, which will really make
identifying resource leaks easier on the server side!

Added a few more log statements too around joining/creating/leaving
tables. This is all important for manual resource debugging.

If you can't tell, I had one player "Playing" for 4 days now :) ... if
only I had proper logging to tell where I went wrong!

Diffstat:
Mlib/Euchre/Host.pm | 13++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/lib/Euchre/Host.pm b/lib/Euchre/Host.pm @@ -5,6 +5,8 @@ use warnings; package Euchre::Host; +use Mojo::Log; + use Euchre::Errors; use Euchre::Dealer; use Euchre::Player; @@ -24,6 +26,8 @@ our %PLAYERS; our %DEALERS; our %PINDEX; # Player id => Dealer id +our $LOG = Mojo::Log->new; + # Stats our $TOTAL_PLAYERS = 0; our $TOTAL_TABLES = 0; @@ -53,7 +57,7 @@ sub gloaters_never_win { my $p = $PLAYERS{$id}; leave_table($p); - printf "Player %s went inactive\n", $p->name; + $LOG->info("Player " . $p->name . " went inactive"); delete $PLAYERS{$id}; } @@ -137,12 +141,14 @@ sub join_table { (exists $msg->{password} ? (password => $msg->{password}) : ()), ); $TOTAL_TABLES++; + $LOG->info("Player " . $p->name . " created table $tid"); } my $d = $DEALERS{$tid}; if (my $errno = $d->add_player($p, $msg->{password})) { $p->error($errno); } else { + $LOG->info("Player " . $p->name . " joined table $tid"); $PINDEX{$p->{id}} = $tid; } } @@ -160,8 +166,9 @@ sub leave_table { # Success! Was removed properly, delete PINDEX # Also delete the Dealer itself if that was the last player # to leave and the game looks finished + $LOG->info("Player " . $p->name . " left table " . $d->id); if (!$d->is_active && $d->game->phase eq 'end') { - printf "Deleting Table %s that appears to have finished\n", $d->id; + $LOG->info("Deleting Table " . $d->id . " that appears to have finished"); delete $DEALERS{$PINDEX{$p->{id}}}; } delete $PINDEX{$p->{id}}; @@ -224,7 +231,7 @@ sub require_keys { sub prune_tables { for my $k (keys %DEALERS) { if (!$DEALERS{$k}->is_active) { - print "Deleting inactive table " . $DEALERS{$k}->id . "\n"; + $LOG->info("Deleting inactive table " . $DEALERS{$k}->id); delete $DEALERS{$k}; } }