aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2021-04-25 14:04:10 +0200
committerlonkaars <loek@pipeframe.xyz>2021-04-25 14:04:10 +0200
commitf020b861915d7269a44f73c417626879c8e0176b (patch)
treeb5e9ef41c9db85da42743f3b98bbf464900cb756
parent06f27a27404e43116bd3dada58fc60dfc3516d44 (diff)
use debug/verbosity from .env in api
-rw-r--r--.env1
-rw-r--r--api/log.py14
-rw-r--r--api/main.py6
-rw-r--r--requirements.txt1
4 files changed, 19 insertions, 3 deletions
diff --git a/.env b/.env
index 246ebb8..06b8db9 100644
--- a/.env
+++ b/.env
@@ -1,3 +1,4 @@
CONNECT4_DEBUG=1
+CONNECT4_LOG_LEVEL=3
CONNECT4_WEB_ROOT="/var/www/..."
diff --git a/api/log.py b/api/log.py
index 1b60670..c006f67 100644
--- a/api/log.py
+++ b/api/log.py
@@ -1,8 +1,18 @@
import logging
+from dotenv import load_dotenv
+from os import environ
+
+load_dotenv()
# logging module wrapper (same as db.py)
-VERBOSE = logging.INFO
-logging.basicConfig(format="[ %(levelname)s ]: %(message)s", level=VERBOSE)
+log_level = [
+ None,
+ logging.ERROR,
+ logging.WARNING,
+ logging.INFO
+ ][int(environ["CONNECT4_LOG_LEVEL"])]
+
+logging.basicConfig(format="[ %(levelname)s ]: %(message)s", level=log_level)
# log functions
error = logging.error
diff --git a/api/main.py b/api/main.py
index 717bb5e..58f9ac1 100644
--- a/api/main.py
+++ b/api/main.py
@@ -1,9 +1,13 @@
import dynamic_import
from app import app
+from dotenv import load_dotenv
+from os import environ
from socket_io import io
import game.socket
+load_dotenv()
+
# start the flask/socket.io server
if __name__ == "__main__":
- io.run(app, host="127.0.0.1", port=5000, debug=True)
+ io.run(app, host="127.0.0.1", port=5000, debug=bool(int(environ["CONNECT4_DEBUG"])))
diff --git a/requirements.txt b/requirements.txt
index c299677..f51b54d 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -13,6 +13,7 @@ Jinja2==2.11.3
MarkupSafe==1.1.1
mergedeep==1.3.4
pycparser==2.20
+python-dotenv==0.17.0
python-engineio==4.1.0
python-socketio==5.2.1
six==1.15.0