Add logging (work in progress...)

This commit is contained in:
Stefano Assenzo 2023-01-07 11:44:09 +00:00
parent 7c30cf9b8f
commit f7ce81ef5d
3 changed files with 18 additions and 1 deletions

3
.gitignore vendored
View File

@ -1,3 +1,4 @@
test.xlsx test.xlsx
.env .env
geckodriver.log geckodriver.log
all.log

16
app.py
View File

@ -1,14 +1,26 @@
from flask import Flask, render_template, request, session, jsonify from flask import Flask, render_template, request, session, jsonify
import requests import requests
import logging
import bcrypt import bcrypt
import sys
import os import os
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s [%(levelname)s] %(message)s",
handlers=[
logging.FileHandler("src/log/all.log"),
logging.StreamHandler(sys.stdout)
]
)
app = Flask(__name__) app = Flask(__name__)
IMAGE_FOLDER = os.path.join('static', 'images') IMAGE_FOLDER = os.path.join('static', 'images')
app.config['UPLOAD_FOLDER'] = IMAGE_FOLDER app.config['UPLOAD_FOLDER'] = IMAGE_FOLDER
@app.route('/') @app.route('/')
def homepage(): def homepage():
logging.info("A user went up: Homepage")
return render_template('html/index.html') return render_template('html/index.html')
#imageList = os.listdir('static/images') #imageList = os.listdir('static/images')
#imageList = ['images/' + image for image in imageList] #imageList = ['images/' + image for image in imageList]
@ -16,20 +28,24 @@ def homepage():
@app.route('/orario') @app.route('/orario')
def orario(): def orario():
logging.info("A user went up: Orario")
if 'username' in session: if 'username' in session:
return "You are logged in as " + session['username'] return "You are logged in as " + session['username']
#return render_template('html/orario.html') #return render_template('html/orario.html')
@app.route('/calendario') @app.route('/calendario')
def calendario(): def calendario():
logging.info("A user went up: Calendario")
return render_template('html/calendario.html') return render_template('html/calendario.html')
# Da sistemare # Da sistemare
@app.route('/api', methods = ['GET', 'POST']) @app.route('/api', methods = ['GET', 'POST'])
def api(): def api():
logging.info("A user went up: API")
if(request.method == 'GET'): if(request.method == 'GET'):
data = "hello world" data = "hello world"
return jsonify({'data': data}) return jsonify({'data': data})
if __name__ == '__main__': if __name__ == '__main__':
logging.info("Web server started!")
app.run() app.run()

View File