From d601e85f9e423d0e5cd489dfb26412981ddcd50d Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Wed, 17 Jul 2024 11:43:50 -0500 Subject: Reorganise code to do ALL configs at the top and then logging In order to ensure that logging works as expected, make sure it is set up after all settings are in place. --- gn2/wqflask/__init__.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'gn2/wqflask') diff --git a/gn2/wqflask/__init__.py b/gn2/wqflask/__init__.py index d651005a..ce42ce4e 100644 --- a/gn2/wqflask/__init__.py +++ b/gn2/wqflask/__init__.py @@ -77,7 +77,7 @@ def dev_loggers(appl: Flask) -> None: root_logger = logging.getLogger() root_logger.addHandler(stderr_handler) - root_logger.setLevel(appl.config.get("LOGLEVEL", "WARNING")) + root_logger.setLevel(appl.config.get("LOG_LEVEL", "WARNING")) def gunicorn_loggers(appl: Flask) -> None: @@ -94,12 +94,20 @@ def setup_logging(appl: Flask) -> None: app = Flask(__name__) -setup_logging(app) - +## BEGIN: Setup configurations ## # See http://flask.pocoo.org/docs/config/#configuring-from-files # Note no longer use the badly named WQFLASK_OVERRIDES (nyi) app.config.from_object('gn2.default_settings') app.config.from_envvar('GN2_SETTINGS') +app.config["SESSION_REDIS"] = redis.from_url(app.config["REDIS_URL"]) +# BEGIN: SECRETS -- Should be the last of the settings to load +secrets_file = Path(app.config.get("GN2_SECRETS", "")).absolute() +if secrets_file.exists() and secrets_file.is_file(): + app.config.from_pyfile(str(secrets_file)) +# END: SECRETS +## END: Setup configurations ## +setup_logging(app) +### DO NOT USE logging BEFORE THIS POINT!!!! ### app.jinja_env.globals.update( undefined=jinja2.StrictUndefined, @@ -110,14 +118,6 @@ app.jinja_env.globals.update( num_collections=numcoll, datetime=datetime) -app.config["SESSION_REDIS"] = redis.from_url(app.config["REDIS_URL"]) - -## BEGIN: SECRETS -- Should be the last of the settings to load -secrets_file = Path(app.config.get("GN2_SECRETS", "")).absolute() -if secrets_file.exists() and secrets_file.is_file(): - app.config.from_pyfile(str(secrets_file)) -## END: SECRETS - # Registering blueprints app.register_blueprint(glossary_blueprint, url_prefix="/glossary") -- cgit v1.2.3