Skip to content

Commit c2b7a66

Browse files
authored
bpo-43731: Add an encoding parameter to logging.fileConfig() (GH-25273)
1 parent a483388 commit c2b7a66

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

Doc/library/logging.config.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ in :mod:`logging` itself) and defining handlers which are declared either in
7777

7878
.. versionadded:: 3.2
7979

80-
.. function:: fileConfig(fname, defaults=None, disable_existing_loggers=True)
80+
.. function:: fileConfig(fname, defaults=None, disable_existing_loggers=True, encoding=None)
8181

8282
Reads the logging configuration from a :mod:`configparser`\-format file. The
8383
format of the file should be as described in
@@ -111,6 +111,8 @@ in :mod:`logging` itself) and defining handlers which are declared either in
111111
they or their ancestors are explicitly named
112112
in the logging configuration.
113113

114+
:param encoding: The encoding used to open file when *fname* is filename.
115+
114116
.. versionchanged:: 3.4
115117
An instance of a subclass of :class:`~configparser.RawConfigParser` is
116118
now accepted as a value for ``fname``. This facilitates:
@@ -121,6 +123,9 @@ in :mod:`logging` itself) and defining handlers which are declared either in
121123
application (e.g. based on command-line parameters or other aspects
122124
of the runtime environment) before being passed to ``fileConfig``.
123125

126+
.. versionadded:: 3.10
127+
The *encoding* parameter is added.
128+
124129
.. function:: listen(port=DEFAULT_LOGGING_CONFIG_PORT, verify=None)
125130

126131
Starts up a socket server on the specified port, and listens for new

Lib/logging/config.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
# _listener holds the server object doing the listening
4949
_listener = None
5050

51-
def fileConfig(fname, defaults=None, disable_existing_loggers=True):
51+
def fileConfig(fname, defaults=None, disable_existing_loggers=True, encoding=None):
5252
"""
5353
Read the logging configuration from a ConfigParser-format file.
5454
@@ -66,7 +66,8 @@ def fileConfig(fname, defaults=None, disable_existing_loggers=True):
6666
if hasattr(fname, 'readline'):
6767
cp.read_file(fname)
6868
else:
69-
cp.read(fname)
69+
encoding = io.text_encoding(encoding)
70+
cp.read(fname, encoding=encoding)
7071

7172
formatters = _create_formatters(cp)
7273

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add an ``encoding`` parameter :func:`logging.fileConfig()`.

0 commit comments

Comments
 (0)