From 0fd5e9f789f58720351411d87422503a40b089d5 Mon Sep 17 00:00:00 2001 From: elpatron68 Date: Mon, 27 May 2024 11:21:57 +0200 Subject: [PATCH] Basic logging for debug purpose --- app.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/app.py b/app.py index 3f57f2b..f5ca01e 100644 --- a/app.py +++ b/app.py @@ -5,6 +5,17 @@ from flask_bootstrap import Bootstrap app = Flask(__name__) app.config['SECRET_KEY'] = 'j69ol5mcHLsEtLg4Y/+myd9wWD4pp56E' + +# set up logging +formatter = logging.Formatter( # pylint: disable=invalid-name + '%(asctime)s %(levelname)s %(process)d ---- %(threadName)s ' + '%(module)s : %(funcName)s {%(pathname)s:%(lineno)d} %(message)s','%Y-%m-%dT%H:%M:%SZ') +handler = logging.StreamHandler() +handler.setFormatter(formatter) +app.logger.setLevel(logging.DEBUG) +app.logger.addHandler(handler) +app.logger.info('Starting erdbeerhannah v1.0.3') + Bootstrap(app) gesamtwert = 0 @@ -27,6 +38,7 @@ def index(): # wert = float(request.form["wert"]) wert = request.form.get('wert', "0", type=float) given = request.form.get('given', "0", type=float) + app.logger.debug('wert: %s, given: %s', wert, given) wertfloat = float(wert) givenfloat = float(given) @@ -68,9 +80,8 @@ def index(): gesamtwert = session['summefloat'] or 0 sum = str(gesamtwert) + "0" change = str(round((givenfloat - gesamtwert) * -1, 2)) + "0" - logging.info('Sum %s, given %s, change %s', sum, givenfloat, change) except: - logging.warning("Failed to read sum") + app.logger.warning("Failed to read sum") if givenfloat - gesamtwert < 0: background = "bg-danger" else: @@ -87,6 +98,8 @@ def index(): session['change'] = change session['given'] = givenfloat + app.logger.info('Sum %s, given %s, change %s', sum, givenfloat, change) + return render_template("index.html", gesamtwert=session.get('summestring', 0), change=session.get('change', 0), given=session.get('given', 0), @@ -110,5 +123,5 @@ def favicon(): # 'about.html') if __name__ == "__main__": - logging.info('Starting erdbeerhannah v1.0.3') + app.logger.info('Starting erdbeerhannah v1.0.3') app.run(debug=True, host='0.0.0.0') \ No newline at end of file