【发布时间】:2020-08-08 10:20:30
【问题描述】:
我们正在使用 alembic 来应用数据库修订。我已经配置了连接,它按预期工作,但我无法让它使用我们的客户记录器。
我们有自己的记录器类(派生自 Python 记录),它在整个应用程序中使用,我希望 alembic 使用它而不是默认值。
有什么方法可以将我们类的记录器对象传递给它吗?我希望它使用自定义记录器中定义的格式和处理程序打印自己的日志。
我试过了,
环境文件
from sqlalchemy import engine_from_config
from sqlalchemy import pool
from alembic import context
from tools.logger import Logger
# this is the Alembic Config object, which provides
# access to the values within the .ini file in use.
config = context.config
# Interpret the config file for Python logging.
# This line sets up loggers basically.
if config.attributes.get('configure_logger', True):
fileConfig(config.config_file_name)
logger = Logger('alembic.env')
我的脚本
self.alembic_cfg = alembic_config(self.alembic_ini_path, attributes={'configure_logger': False})
我也试过了,
self.alembic_cfg.set_section_option("logger", "keys", "root")
以上两种方法都只是禁用自己的日志。
【问题讨论】:
标签: python logging sqlalchemy alembic flask-migrate