]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-43731: Add an `encoding` parameter to logging.fileConfig() (GH-25273)
authorInada Naoki <songofacandy@gmail.com>
Tue, 13 Apr 2021 09:17:03 +0000 (18:17 +0900)
committerGitHub <noreply@github.com>
Tue, 13 Apr 2021 09:17:03 +0000 (18:17 +0900)
Doc/library/logging.config.rst
Lib/logging/config.py
Misc/NEWS.d/next/Library/2021-04-08-15-19-20.bpo-43731.nnVd3h.rst [new file with mode: 0644]

index cab49f6072f357aa31c467e73a238f055cc895f8..f833bcdd1fcf5b7e74870ec4e2c2a4f332ca5022 100644 (file)
@@ -77,7 +77,7 @@ in :mod:`logging` itself) and defining handlers which are declared either in
 
    .. versionadded:: 3.2
 
-.. function:: fileConfig(fname, defaults=None, disable_existing_loggers=True)
+.. function:: fileConfig(fname, defaults=None, disable_existing_loggers=True, encoding=None)
 
    Reads the logging configuration from a :mod:`configparser`\-format file. The
    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
                                     they or their ancestors are explicitly named
                                     in the logging configuration.
 
+    :param encoding: The encoding used to open file when *fname* is filename.
+
    .. versionchanged:: 3.4
       An instance of a subclass of :class:`~configparser.RawConfigParser` is
       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
         application (e.g. based on command-line parameters or other aspects
         of the runtime environment) before being passed to ``fileConfig``.
 
+    .. versionadded:: 3.10
+       The *encoding* parameter is added.
+
 .. function:: listen(port=DEFAULT_LOGGING_CONFIG_PORT, verify=None)
 
    Starts up a socket server on the specified port, and listens for new
index fd3aded7608cbfebcc7002d456aa3b631eec9453..3bc63b78621abae6b697f4f0d5b122ae5750a312 100644 (file)
@@ -48,7 +48,7 @@ RESET_ERROR = errno.ECONNRESET
 #   _listener holds the server object doing the listening
 _listener = None
 
-def fileConfig(fname, defaults=None, disable_existing_loggers=True):
+def fileConfig(fname, defaults=None, disable_existing_loggers=True, encoding=None):
     """
     Read the logging configuration from a ConfigParser-format file.
 
@@ -66,7 +66,8 @@ def fileConfig(fname, defaults=None, disable_existing_loggers=True):
         if hasattr(fname, 'readline'):
             cp.read_file(fname)
         else:
-            cp.read(fname)
+            encoding = io.text_encoding(encoding)
+            cp.read(fname, encoding=encoding)
 
     formatters = _create_formatters(cp)
 
diff --git a/Misc/NEWS.d/next/Library/2021-04-08-15-19-20.bpo-43731.nnVd3h.rst b/Misc/NEWS.d/next/Library/2021-04-08-15-19-20.bpo-43731.nnVd3h.rst
new file mode 100644 (file)
index 0000000..e5309c9
--- /dev/null
@@ -0,0 +1 @@
+Add an ``encoding`` parameter :func:`logging.fileConfig()`.