alembic icon indicating copy to clipboard operation
alembic copied to clipboard

pass `context.config.config_args` to `logging.config.fileConfig`

Open jvanasco opened this issue 7 months ago • 5 comments

Some projects, like Pyramid, support %(here)s interpolation in .ini files for logging.

Extending Alembic to support this is trivial. The data is already computed as part of config.config_args. The env.py files just need to pass in these args as defaults:

  • fileConfig(config.config_file_name)
    
  • fileConfig(config.config_file_name, defaults=config.config_args)
    

jvanasco avatar Jun 11 '25 17:06 jvanasco

how is this fitting into what you're doing ? is this for paths to log files? all the alembic script locations etc. I think are already consumed by the time you get to env.py

zzzeek avatar Jun 11 '25 19:06 zzzeek

is this for paths to log files?

Yes.

jvanasco avatar Jun 11 '25 19:06 jvanasco

if we do change this part, maybe we could add also the other flag suggested here? https://github.com/sqlalchemy/alembic/discussions/1483#discussioncomment-9920270

CaselIT avatar Jun 17 '25 19:06 CaselIT

if we do change this part, maybe we could add also the other flag suggested here? https://github.com/sqlalchemy/alembic/discussions/1483#discussioncomment-9920270

A quick online search suggests that may be a good idea. It seems to cause issues on many projects.

An alternative for both would just be putting some inline comments on the generated env.py file, pointing people how to do these things.

jvanasco avatar Jun 17 '25 19:06 jvanasco

maybe we could add both providing inline docs to the rationale about the args? Something like

fileConfig(
  config.config_file_name,
  # used for ...
  defaults=config.config_args,
  # ...
  disable_existing_loggers=False,
)

CaselIT avatar Jun 17 '25 20:06 CaselIT