Skip to main content

Command Palette

Search for a command to run...

Alembic disables my logs

Updated
1 min read
Alembic disables my logs
D

I am developer/code-reviewer/debugger/bug-fixer/architect/teacher/builder from dubai, uae

…and how to get them back

Alembic is SQLAlchemy's database migration framework—think change management for your relational database. It autogenerates scripts tracking your ORM model changes, letting you recreate your data model at any point in time.

Most apps run migrations on startup. I noticed my logs would mysteriously vanish right after the migration check.

The culprit? This innocent-looking snippet in the auto-generated env.py:

if config.config_file_name is not None:
    fileConfig(config.config_file_name)

That fileConfig defaults to disable_existing_loggers=True (thanks, backwards compatibility!), nuking any logging you previously configured.

The fix: Either edit the generated env.py or configure your logging after migrations run.

Happy hackin'

References: