浏览代码

Add some basic logging to game stuff

Pjotir 10 月之前
父节点
当前提交
f12aef1506
共有 1 个文件被更改,包括 11 次插入0 次删除
  1. 11 0
      flaskapp.py

+ 11 - 0
flaskapp.py

@@ -8,12 +8,17 @@ from flask import (
     url_for,
 )
 
+import logging
 from game import Game, randomword
 
 app = Flask(__name__)
 app.secret_key = "somebullshit"
 app.games = []
 
+logging.basicConfig(
+    level=logging.DEBUG, format="%(asctime)s - %(levelname)s - %(message)s"
+)
+
 
 @app.route("/")
 def home():
@@ -23,11 +28,14 @@ def home():
 @app.route("/newgame")
 def new_game():
     try:
+        app.logger.info("Creating game...")
         name = request.args["playerName"]
         hand_size = request.args["handSize"]
         match_count = request.args["matchCount"]
         turn_count = request.args["turnCount"]
     except (KeyError, TypeError) as e:
+        app.logger.error(e)
+        app.logger.error("Failed, bad args")
         return abort(400)
 
     game_id = None
@@ -35,6 +43,9 @@ def new_game():
         if game_id not in [game.id for game in app.games]:
             break
 
+    app.logger.info(
+        f"Game created: {game_id} {name} {hand_size} {match_count} {turn_count}"
+    )
     game = Game(name, hand_size, match_count, turn_count, game_id)
     app.games.append(game)
     session["game_id"] = game.id