Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allowing log_config to accept ConfigParser instance or a file object #1716

Closed
wants to merge 1 commit into from
Closed

Conversation

antonymayi
Copy link
Contributor

The existing logic for the log_config option accepts:

  • dict or str representing a JSON or YAML file name to be parsed using logging.config.dictConfig
  • str representing an INI file name to be parsed using logging.config.fileConfig

The logging.config.fileConfig, however, accepts not only the file name, but possibly also an instance of configparser.RawConfigParser and even an open file object. Passing the instance of configparser.RawConfigParser (or its subclass) would be especially useful as this can accumulate configs from multiple files (cp.read() can be called repeatedly on different files updating its config values) instead of just a single one.

I am proposing this trivial change to allow the log_config option to also accept the *ConfigParser instance or a general file object.

@Kludex
Copy link
Sponsor Member

Kludex commented Oct 22, 2022

I didn't even know about ConfigParser 🤣

Anyway... Can you show me an example on how you use this? A self-contained repository that uses this branch is enough.

Also, we need to add a test for it. 👀

@antonymayi
Copy link
Contributor Author

re the usage example:

I use uvicorn as a specific plugin within the ForML framework which itself is using its own logging config potentially combining multiple user-provided INI files loaded (via the LOGGING.read()) into a single ConfigParser instance.

It would be convenient to be able to pass that instance to the uvicorn setup as shown here (working example based on my PR).

I've updated the PR with the test_log_config_file now covering not just a string file name but also an instance of a ConfigParser and a file-like object.

@antonymayi
Copy link
Contributor Author

Hi @Kludex, happy to update the PR based on your further guidelines in case you have any?

Copy link
Contributor

@iudeen iudeen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this! 👍

@Kludex
Copy link
Sponsor Member

Kludex commented Nov 1, 2022

Is there any big project that uses ConfigParser?

@Kludex Kludex added the logging label Nov 1, 2022
@Kludex Kludex added this to the Version 0.21.0 milestone Nov 1, 2022
@antonymayi
Copy link
Contributor Author

Is there any big project that uses ConfigParser?

Depends on the definition of a big project but I believe Apache Airflow for instance should be a fit beyond any doubt.

Copy link
Sponsor Member

@Kludex Kludex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the amount of work needed for you if this PR is not accepted?

@Kludex Kludex added the waiting author Waiting for author's reply label Dec 31, 2022
@antonymayi
Copy link
Contributor Author

What is the amount of work needed for you if this PR is not accepted?

Making my life better or worse shouldn't be the concern here (even though I appreciate the consideration).

Can you please briefly clarify your reservations about this feature? Do you see any issues or do you just think it is a marginal use case and hence not worth it?

The way I see it, this really makes it way easier to integrate uvicorn logging within any embedding project. Without it, uvicorn is forcing the embedding application to use a single physical file (why single? why physical?) or essentially a hand-written (since there is no standard API to produce it programmatically) dictionary. This seems unnecessarily too demanding from a component within an embedding project (especially if it is not even a central component like in my case).

Had uvicorn supported just ConfigParser and not any of the other current options (files/dict), it would still have supported all these usecases (it is possible to create ConfigParser instance from files/dict) but not the other way round. So ConfigParser should have imho always been the primary option and only then considering the other ways (explicit files/dict) as convenient cosmetical shortcuts.

@Kludex Kludex mentioned this pull request Mar 10, 2023
16 tasks
@Kludex Kludex modified the milestones: Version 0.21.0, Version 0.22.0 Mar 22, 2023
@antonymayi antonymayi closed this by deleting the head repository May 13, 2023
@antonymayi
Copy link
Contributor Author

I accidentally deleted the forked repository which automatically closed this PR. I am opening a new one as #1976, apologies for the inconvenience.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
logging waiting author Waiting for author's reply
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants