Basic logging for debug purpose

This commit is contained in:
elpatron68
2024-05-27 11:21:57 +02:00
parent f6acec036a
commit 0fd5e9f789

19
app.py
View File

@@ -5,6 +5,17 @@ from flask_bootstrap import Bootstrap
app = Flask(__name__) app = Flask(__name__)
app.config['SECRET_KEY'] = 'j69ol5mcHLsEtLg4Y/+myd9wWD4pp56E' 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) Bootstrap(app)
gesamtwert = 0 gesamtwert = 0
@@ -27,6 +38,7 @@ def index():
# wert = float(request.form["wert"]) # wert = float(request.form["wert"])
wert = request.form.get('wert', "0", type=float) wert = request.form.get('wert', "0", type=float)
given = request.form.get('given', "0", type=float) given = request.form.get('given', "0", type=float)
app.logger.debug('wert: %s, given: %s', wert, given)
wertfloat = float(wert) wertfloat = float(wert)
givenfloat = float(given) givenfloat = float(given)
@@ -68,9 +80,8 @@ def index():
gesamtwert = session['summefloat'] or 0 gesamtwert = session['summefloat'] or 0
sum = str(gesamtwert) + "0" sum = str(gesamtwert) + "0"
change = str(round((givenfloat - gesamtwert) * -1, 2)) + "0" change = str(round((givenfloat - gesamtwert) * -1, 2)) + "0"
logging.info('Sum %s, given %s, change %s', sum, givenfloat, change)
except: except:
logging.warning("Failed to read sum") app.logger.warning("Failed to read sum")
if givenfloat - gesamtwert < 0: if givenfloat - gesamtwert < 0:
background = "bg-danger" background = "bg-danger"
else: else:
@@ -87,6 +98,8 @@ def index():
session['change'] = change session['change'] = change
session['given'] = givenfloat 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), return render_template("index.html", gesamtwert=session.get('summestring', 0),
change=session.get('change', 0), change=session.get('change', 0),
given=session.get('given', 0), given=session.get('given', 0),
@@ -110,5 +123,5 @@ def favicon():
# 'about.html') # 'about.html')
if __name__ == "__main__": 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') app.run(debug=True, host='0.0.0.0')