Browse Source

added logging, log ip of user

Bernadette Elena Hammerle 1 year ago
parent
commit
94414d5f98
1 changed files with 16 additions and 6 deletions
  1. 16 6
      app.py

+ 16 - 6
app.py

@@ -7,15 +7,22 @@ Created on Sat Apr 22 17:07:13 2022
 import time
 import json
 import requests
+import logging
 from flask import Flask, render_template, request, flash
+from werkzeug.middleware.proxy_fix import ProxyFix
 
 
-# FOLDER = "src/"  # docker
-FOLDER = ""  # local
-
+FOLDER = "src/"  # docker
+# FOLDER = ""  # local
 
 app = Flask(__name__)
-app.config["TEMPLATES_AUTO_RELOAD"] = True
+app.wsgi_app = ProxyFix(app.wsgi_app)
+
+# w_log = logging.getLogger("werkzeug")
+# w_log.disabled = True
+app.logger.setLevel(logging.INFO)
+
+# app.config["TEMPLATES_AUTO_RELOAD"] = True
 with open(f"{FOLDER}secret_key", "rb") as secretKeyFile:
     app.secret_key = secretKeyFile.read()
 
@@ -56,7 +63,10 @@ def contribute():
             "message": request.form.get("message"),
             "timestamp": time.time()
         }
+
         add_to_database("contribute", contribution)
+        logging.info(contribution)
+        app.logger.info(contribution)
 
         flash("Danke für's Mitmachen!", "success")
     return render_template("contribute.html")
@@ -76,5 +86,5 @@ def add_to_database(db_name, data_to_add):
 
 
 if __name__ == "__main__":
-    app.run()  # localhost
-    # app.run(host="0.0.0.0")  # in network
+    # app.run()  # localhost
+    app.run(host="0.0.0.0")  # in network