Skip to content

gh-93162: Allow passing instances of logging objects to logging.dictConfig #93163

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

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion Lib/logging/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,9 @@ def configure(self):

def configure_formatter(self, config):
"""Configure a formatter from a dictionary."""
if isinstance(config, logging.Formatter):
return config

if '()' in config:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Using '()' would be more consistent with handler configuration but then the entry in the dict is just

{
    '()': my_object
}

Copy link
Member

Choose a reason for hiding this comment

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

Doesn't that work?

factory = config['()'] # for use in exception handler
try:
Expand Down Expand Up @@ -683,6 +686,9 @@ def configure_formatter(self, config):

def configure_filter(self, config):
"""Configure a filter from a dictionary."""
if isinstance(config, logging.Filter):
return config

if '()' in config:
result = self.configure_custom(config)
else:
Expand Down Expand Up @@ -744,7 +750,7 @@ def configure_handler(self, config):
props = config.pop('.', None)
kwargs = {k: config[k] for k in config if valid_ident(k)}
try:
result = factory(**kwargs)
result = factory(**kwargs) if not isinstance(factory, logging.Handler) else factory
except TypeError as te:
if "'stream'" not in str(te):
raise
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Allow passing instances of logging objects to logging.dictConfig