diff --git a/backend/app.py b/backend/app.py index 5607a8d27bdbe19088ebc1f03b37b2d96999cb88..01436ce6374ecb4a190e2243a9a6c6c6027c6bd9 100644 --- a/backend/app.py +++ b/backend/app.py @@ -46,7 +46,7 @@ from logging.config import dictConfig dictConfig({ 'version': 1, 'formatters': {'default': { - 'format': '[%(asctime)s] %(levelname)s in %(module)s: %(message)s', + 'format': '[%(asctime)s] %(levelname)s in %(name)s (%(filename)s+%(lineno)d): %(message)s', }}, 'handlers': {'wsgi': { 'class': 'logging.StreamHandler', @@ -56,7 +56,10 @@ dictConfig({ 'root': { 'level': 'INFO', 'handlers': ['wsgi'], - } + }, + # Loggers are created also by alembic, flask_migrate, etc. Without this + # setting, those loggers seem to be ignored. + 'disable_existing_loggers': False, }) app = Flask(__name__) @@ -78,7 +81,14 @@ def init_routines(): # This checks whether we need to prepare the database to follow that # change. migration_reset.reset() + app.logger.info("Loading flask_migrate.") + # flask_migrate exits the program when it encounters an error, for example + # when the version set in the database is not found in the + # `migrations/versions` directory. We could prevent that by catching the + # `SystemExit` exception here, but actually it's not safe to continue in + # that case. flask_migrate.Migrate(app, db) + app.logger.info("Attempting flask_migrate database upgrade.") try: with app.app_context(): flask_migrate.upgrade() @@ -97,11 +107,11 @@ def init_routines(): # Same for the list of oauthclients. cluster_config.populate_oauthclients() -# `init_routines`should only run once per dashboard instance. To enforce this we -# have different behaviour for production and development mode: -# * we have "preload" on for gunicorn, so this file is loaded only once, before -# workers are forked (production); -# * we make sure that in development mode we run this only once, even though +# `init_routines` should only run once per dashboard instance. To enforce this +# we have different behaviour for production and development mode: +# * We have "preload" on for gunicorn, so this file is loaded only once, before +# workers are forked (production). +# * We make sure that in development mode we run this only once, even though # this file is loaded twice by flask for some reason. if RUN_BY_GUNICORN: logging.info("Running initialization code (production mode).")