Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How i can disable alembic logging at runtime?

I need to disable alembic migrations logging, while executing migrations in unit tests, .

I can't just remove alembic logger it from alembic.ini: i need this output while performing migrations myself.

Following did not work for me: logging.getLogger('alembic').setLevel(logging.CRITICAL)

How i can disable it at runtime?

like image 662
avasin Avatar asked May 18 '16 22:05

avasin


People also ask

How do I downgrade alembic?

If you want to run to downgrade() of a version, you will need to run alembic downgrade the-version-before-it , which mean it will revert to the version after the version that you want to downgrade. Which is the version before the version that we want to revert.

Where does alembic store migrations?

yourproject - this is the root of your application's source code, or some directory within it. alembic - this directory lives within your application's source tree and is the home of the migration environment.

How does alembic migration work?

This is where we will write our migrations. Alembic created a unique id and empty upgrade and downgrade functions. Upgrade contains the code that executes when we run our migration whereas downgrade contains the code executed when we rollback a migration.

What is alembic INI file?

alembic init alembic From there, you can create tables or migrate functions for example. After the init command, a folder structure is created. The file named 'alembic.ini' is called every time Alembic is used. It contains all the basic information that makes it possible to connect to the database of your choice.


2 Answers

You need to edit the alembic.ini file and change the logging setting for this particular log. You can read about it in the relevant section of the Alembic tutorial. By default, this section should be in your configuration file:

[logger_alembic]
level = INFO
handlers =
qualname = alembic

I set mine to WARN instead, and these logs went away.

like image 101
Brian Peterson Avatar answered Sep 24 '22 13:09

Brian Peterson


Sounds like you're invoking Alembic from within your unit tests by calling out to the alembic command, which is a separate process and does not inherit your logging configuration.

Instead, you should invoke Alembic programmatically:

import logging
import alembic.config
import alembic.command

logging.getLogger('alembic').setLevel(logging.CRITICAL)

alembic_cfg = alembic.config.Config('alembic.ini')
alembic.command.upgrade(alembic_cfg, 'head')

See the documentation for more info about the Alembic API.

like image 25
Søren Løvborg Avatar answered Sep 24 '22 13:09

Søren Løvborg