Add logging to log file.
This commit is contained in:
3
app.py
3
app.py
@@ -1,10 +1,13 @@
|
||||
import functools
|
||||
import logging
|
||||
from flask import Flask, g, render_template, request, redirect, session
|
||||
|
||||
import db
|
||||
import models
|
||||
|
||||
|
||||
logging.basicConfig(filename='estus-shots.log', level=logging.DEBUG)
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
app.secret_key = 'THIS IS A TEST KEY'
|
||||
|
||||
4
db.py
4
db.py
@@ -12,6 +12,7 @@ def connect_db():
|
||||
"""Create a new sqlite3 connection and register it in 'g._database'"""
|
||||
db = getattr(g, '_database', None)
|
||||
if db is None:
|
||||
log.info(f'Connecting {DATABASE}')
|
||||
db = g._database = sqlite3.connect(DATABASE)
|
||||
|
||||
db.row_factory = sqlite3.Row
|
||||
@@ -20,7 +21,7 @@ def connect_db():
|
||||
|
||||
def query_db(query, args=(), one=False, cls=None):
|
||||
"""Runs an SQL query on an new database connection, returning the fetched rv"""
|
||||
log.info(f'Running query ({query})\nwith arguments ({args})')
|
||||
log.info(f'Running query ({query}) with arguments ({args})')
|
||||
cur = connect_db().execute(query, args)
|
||||
rv = cur.fetchall()
|
||||
cur.close()
|
||||
@@ -39,6 +40,7 @@ def update_db(query, args=()):
|
||||
con.cursor().execute(query, args)
|
||||
except sqlite3.Error as err:
|
||||
return err
|
||||
else:
|
||||
con.commit()
|
||||
return False
|
||||
|
||||
|
||||
Reference in New Issue
Block a user