Skip to content

Commit

Permalink
Using APP_ENV to define ENV_LOG_FLAG (partially #107)
Browse files Browse the repository at this point in the history
  • Loading branch information
alanwilter committed Sep 4, 2020
1 parent 26515a4 commit a52e4cf
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
7 changes: 7 additions & 0 deletions views/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@
from logging.config import dictConfig
from flask.logging import default_handler

# Options are: prod, dev, debug (default), test (for coverage)
APP_ENV = os.getenv("APP_ENV", "debug")

ENV_LOG_FLAG = True
if APP_ENV in ["test", "prod"]:
ENV_LOG_FLAG = False


def _configure_logs():
dictConfig(
Expand Down
4 changes: 2 additions & 2 deletions views/postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from flask import g
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker, Session
from views import application
from views import application, ENV_LOG_FLAG


def get_db():
Expand All @@ -25,7 +25,7 @@ def get_db_session() -> Session:
current application context.
"""
if not hasattr(g, "dbsession"):
engine = create_engine(application.config["SQLALCHEMY_DATABASE_URI"], echo=True)
engine = create_engine(application.config["SQLALCHEMY_DATABASE_URI"], echo=ENV_LOG_FLAG)
engine.connect()
DbSession = sessionmaker(bind=engine)
DbSession.configure(bind=engine)
Expand Down

0 comments on commit a52e4cf

Please sign in to comment.