This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: Allow `logging.config.fileConfig` to accept kwargs
Type: enhancement Stage: resolved
Components: Library (Lib) Versions:
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: planders, vinay.sajip
Priority: normal Keywords:

Created on 2017-07-30 17:10 by planders, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 2979 merged planders, 2017-08-01 23:32
Messages (6)
msg299502 - (view) Author: Preston Landers (planders) * Date: 2017-07-30 17:10
The function `logging.config.fileConfig` accepts `args` but it would be nice if it also accepted `kwargs`.

A simple patch seems to do it:

	diff --git a/Lib/logging/ b/Lib/logging/
	index d692514..4672b48 100644
	--- a/Lib/logging/
	+++ b/Lib/logging/
	@@ -145,7 +145,9 @@ def _install_handlers(cp, formatters):
				 klass = _resolve(klass)
			 args = section["args"]
			 args = eval(args, vars(logging))
	-        h = klass(*args)
	+        kwargs = section.get("kwargs", '{}')
	+        kwargs = eval(kwargs, vars(logging))
	+        h = klass(*args, **kwargs)
			 if "level" in section:
				 level = section["level"]

Unless there are any objections I plan to submit a pull request. In my use case I have a Pyramid service which
uses `concurrent-log-handler` and it seems better to be able to name keyword args for file configuration.
msg299586 - (view) Author: Preston Landers (planders) * Date: 2017-07-31 20:37
This is the current state of my patch:


It makes both `args` and `kwargs` optional in the config file. (Obviously, the actual handler may require args.)
msg299632 - (view) Author: Vinay Sajip (vinay.sajip) * (Python committer) Date: 2017-08-01 19:07
Yes, seems reasonable, but don't change Misc/NEWS directly in your patch - this is now done using the "blurb" tool. Installed into a Python 3 environment using "pip install blurb".
msg299671 - (view) Author: Vinay Sajip (vinay.sajip) * (Python committer) Date: 2017-08-02 20:44
New changeset 6ea56d2ebcae69257f8dd7af28c357b25bf394c3 by Vinay Sajip (Preston Landers) in branch 'master':
bpo-31080: Allowed logging.config.fileConfig() to accept both args and kwargs. (GH-2979)
msg299677 - (view) Author: Preston Landers (planders) * Date: 2017-08-02 22:51
A colleague pointed out that I used single quotes in the defaults where the line uses double quotes for another argument. I'm not sure if this is considered a problem but I could submit an update if it is.
msg299691 - (view) Author: Vinay Sajip (vinay.sajip) * (Python committer) Date: 2017-08-03 08:43
No, that's OK - leave it as is, I'll consider it when next visiting the area.
Date User Action Args
2022-04-11 14:58:49adminsetgithub: 75263
2017-08-03 08:43:28vinay.sajipsetmessages: + msg299691
2017-08-02 22:51:15planderssetmessages: + msg299677
2017-08-02 21:22:00vinay.sajipsetstatus: open -> closed
resolution: fixed
stage: resolved
2017-08-02 20:44:32vinay.sajipsetmessages: + msg299671
2017-08-01 23:32:10planderssetpull_requests: + pull_request3021
2017-08-01 19:07:08vinay.sajipsetmessages: + msg299632
2017-07-31 20:37:01planderssetmessages: + msg299586
2017-07-31 20:27:14pitrousetnosy: + vinay.sajip
2017-07-30 17:10:10planderscreate