Skip to content
This repository was archived by the owner on Dec 19, 2021. It is now read-only.

Commit d68c804

Browse files
Enable user to turn off/on logging from sqlalchemy (#388)
* Enable user to turn off/on logging from sqlalchemy Sometimes the logging is useful, but other times it just gets in the way. Enable the user to turn off/on logging as they desire from their .env file. * Update app.py Co-authored-by: Tyler Norbury <TNorbury@users.noreply.github.com> Co-authored-by: Tyler Norbury <TNorbury@users.noreply.github.com>
1 parent beb4451 commit d68c804

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

.env.example

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
SECRET_KEY='dwellingly'
22
PYTHONPATH=${PWD}:${PYTHONPATH}
33

4-
# To set the database to postgresql. Uncomment the env vars below
4+
## Uncomment to see logging from sqlalchemy
5+
# DB_LOGGING=ON
6+
7+
## To set the database to postgresql. Uncomment the env vars below
58
# DEV_DATABASE_URL=postgresql://localhost/dwellingly_development
69
# TEST_DATABASE_URL=postgresql://localhost/dwellingly_test

app.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os
12
import logging
23
from flask import Flask
34
from flask_jwt_extended import JWTManager
@@ -55,8 +56,10 @@ def check_if_token_in_blocklist(jwt_header, decrypted_token):
5556
def format_unauthorized_message(message):
5657
return {app.config["JWT_ERROR_MESSAGE_KEY"]: message.capitalize()}, 401
5758

58-
logging.basicConfig()
59-
logging.getLogger("sqlalchemy.engine").setLevel(logging.INFO)
59+
if os.getenv("DB_LOGGING") == "ON":
60+
logging.basicConfig()
61+
logging.getLogger("sqlalchemy.engine").setLevel(logging.INFO)
62+
6063
db.init_app(app)
6164
ma.init_app(app)
6265
return app

0 commit comments

Comments
 (0)