From 3dcba71a6d09f2b11df50fbfd86bda8950449991 Mon Sep 17 00:00:00 2001 From: Michael Weimann Date: Mon, 21 Jun 2021 17:35:28 +0200 Subject: [PATCH] add logging --- README.md | 1 - app.py | 10 ++++++++-- env.dev | 6 ++++++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 7a38e97..8076384 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,6 @@ rm data/ki.sqlite cp env.dev .env pipenv install --dev pipenv shell -export FLASK_APP=app.py flask db upgrade flask seed flask run diff --git a/app.py b/app.py index db05bb2..478a6be 100644 --- a/app.py +++ b/app.py @@ -1,3 +1,4 @@ +import logging import os from dotenv import load_dotenv, find_dotenv @@ -7,9 +8,14 @@ from flask_migrate import Migrate load_dotenv(find_dotenv()) +loglevel = os.getenv("KI_LOGLEVEL", logging.WARNING) +loglevel = int(loglevel) +logging.basicConfig(level=loglevel) +logging.debug("Hello from KI") + app = Flask(__name__) -app.config['SQLALCHEMY_DATABASE_URI'] = os.getenv("SQLALCHEMY_DATABASE_URI") -app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False +app.config["SQLALCHEMY_DATABASE_URI"] = os.getenv("SQLALCHEMY_DATABASE_URI") +app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False app.config["KI_DATA_DIR"] = os.path.dirname(__file__) + "/data" app.config["KI_AUTH"] = os.getenv("KI_AUTH") db = SQLAlchemy(app) diff --git a/env.dev b/env.dev index 608ae12..05bc64d 100644 --- a/env.dev +++ b/env.dev @@ -1,3 +1,9 @@ SQLALCHEMY_DATABASE_URI = 'sqlite:///data/ki.sqlite' +FLASK_APP=app.py +FLASK_ENV=development + KI_AUTH=file + +# 10 = debug +KI_LOGLEVEL=10 -- 2.30.2