summaryrefslogtreecommitdiffstats
path: root/Doc/howto
diff options
context:
space:
mode:
authorVinay Sajip <vinay_sajip@yahoo.co.uk>2019-06-17 16:40:52 (GMT)
committerGitHub <noreply@github.com>2019-06-17 16:40:52 (GMT)
commitca7b504a4d4c3a5fde1ee4607b9501c2bab6e743 (patch)
tree00ebd3f37fbd696b8f70765d624447d470496f62 /Doc/howto
parent00f6493084c385033fe5574314223217d9a26672 (diff)
downloadcpython-ca7b504a4d4c3a5fde1ee4607b9501c2bab6e743.zip
cpython-ca7b504a4d4c3a5fde1ee4607b9501c2bab6e743.tar.gz
cpython-ca7b504a4d4c3a5fde1ee4607b9501c2bab6e743.tar.bz2
bpo-37111: Add 'encoding' and 'errors' parameters to logging.basicCon… (GH-14008)
Diffstat (limited to 'Doc/howto')
-rw-r--r--Doc/howto/logging.rst11
1 files changed, 10 insertions, 1 deletions
diff --git a/Doc/howto/logging.rst b/Doc/howto/logging.rst
index 7a68ca8..fbe5a11 100644
--- a/Doc/howto/logging.rst
+++ b/Doc/howto/logging.rst
@@ -128,10 +128,18 @@ look at that next. Be sure to try the following in a newly-started Python
interpreter, and don't just continue from the session described above::
import logging
- logging.basicConfig(filename='example.log',level=logging.DEBUG)
+ logging.basicConfig(filename='example.log', encoding='utf-8', level=logging.DEBUG)
logging.debug('This message should go to the log file')
logging.info('So should this')
logging.warning('And this, too')
+ logging.error('And non-ASCII stuff, too, like Øresund and Malmö')
+
+.. versionchanged:: 3.9
+ The *encoding* argument was added. In earlier Python versions, or if not
+ specified, the encoding used is the default value used by :func:`open`. While
+ not shown in the above example, an *errors* argument can also now be passed,
+ which determines how encoding errors are handled. For available values and
+ the default, see the documentation for :func:`open`.
And now if we open the file and look at what we have, we should find the log
messages:
@@ -141,6 +149,7 @@ messages:
DEBUG:root:This message should go to the log file
INFO:root:So should this
WARNING:root:And this, too
+ ERROR:root:And non-ASCII stuff, too, like Øresund and Malmö
This example also shows how you can set the logging level which acts as the
threshold for tracking. In this case, because we set the threshold to