Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0e82fd1

Browse files
committed
Issue #16884: Merged logging documentation fixes from 3.2.
2 parents e6dec98 + e50f4d2 commit 0e82fd1

File tree

2 files changed

+37
-21
lines changed

2 files changed

+37
-21
lines changed

Doc/howto/logging.rst

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -780,13 +780,14 @@ should have the desired effect. If an organisation produces a number of
780780
libraries, then the logger name specified can be 'orgname.foo' rather than
781781
just 'foo'.
782782

783-
**PLEASE NOTE:** It is strongly advised that you *do not add any handlers other
784-
than* :class:`~logging.NullHandler` *to your library's loggers*. This is
785-
because the configuration of handlers is the prerogative of the application
786-
developer who uses your library. The application developer knows their target
787-
audience and what handlers are most appropriate for their application: if you
788-
add handlers 'under the hood', you might well interfere with their ability to
789-
carry out unit tests and deliver logs which suit their requirements.
783+
.. note:: It is strongly advised that you *do not add any handlers other
784+
than* :class:`~logging.NullHandler` *to your library's loggers*. This is
785+
because the configuration of handlers is the prerogative of the application
786+
developer who uses your library. The application developer knows their
787+
target audience and what handlers are most appropriate for their
788+
application: if you add handlers 'under the hood', you might well interfere
789+
with their ability to carry out unit tests and deliver logs which suit their
790+
requirements.
790791

791792

792793
Logging Levels

Doc/library/logging.rst

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -948,14 +948,14 @@ functions.
948948
Logs a message with level *level* on the root logger. The other arguments are
949949
interpreted as for :func:`debug`.
950950

951-
PLEASE NOTE: The above module-level functions which delegate to the root
952-
logger should *not* be used in threads, in versions of Python earlier than
953-
2.7.1 and 3.2, unless at least one handler has been added to the root
954-
logger *before* the threads are started. These convenience functions call
955-
:func:`basicConfig` to ensure that at least one handler is available; in
956-
earlier versions of Python, this can (under rare circumstances) lead to
957-
handlers being added multiple times to the root logger, which can in turn
958-
lead to multiple messages for the same event.
951+
.. note:: The above module-level functions which delegate to the root
952+
logger should *not* be used in threads, in versions of Python earlier
953+
than 2.7.1 and 3.2, unless at least one handler has been added to the
954+
root logger *before* the threads are started. These convenience functions
955+
call :func:`basicConfig` to ensure that at least one handler is
956+
available; in earlier versions of Python, this can (under rare
957+
circumstances) lead to handlers being added multiple times to the root
958+
logger, which can in turn lead to multiple messages for the same event.
959959

960960
.. function:: disable(lvl)
961961

@@ -1011,12 +1011,12 @@ functions.
10111011
This function does nothing if the root logger already has handlers
10121012
configured for it.
10131013

1014-
PLEASE NOTE: This function should be called from the main thread
1015-
before other threads are started. In versions of Python prior to
1016-
2.7.1 and 3.2, if this function is called from multiple threads,
1017-
it is possible (in rare circumstances) that a handler will be added
1018-
to the root logger more than once, leading to unexpected results
1019-
such as messages being duplicated in the log.
1014+
.. note:: This function should be called from the main thread
1015+
before other threads are started. In versions of Python prior to
1016+
2.7.1 and 3.2, if this function is called from multiple threads,
1017+
it is possible (in rare circumstances) that a handler will be added
1018+
to the root logger more than once, leading to unexpected results
1019+
such as messages being duplicated in the log.
10201020

10211021
The following keyword arguments are supported.
10221022

@@ -1115,6 +1115,21 @@ functions.
11151115
:kwargs: Additional keyword arguments.
11161116

11171117

1118+
Module-Level Attributes
1119+
-----------------------
1120+
1121+
.. attribute:: lastResort
1122+
1123+
A "handler of last resort" is available through this attribute. This
1124+
is a :class:`StreamHandler` writing to ``sys.stderr`` with a level of
1125+
``WARNING``, and is used to handle logging events in the absence of any
1126+
logging configuration. The end result is to just print the message to
1127+
``sys.stderr``. This replaces the earlier error message saying that
1128+
"no handlers could be found for logger XYZ". If you need the earlier
1129+
behaviour for some reason, ``lastResort`` can be set to ``None``.
1130+
1131+
.. versionadded:: 3.2
1132+
11181133
Integration with the warnings module
11191134
------------------------------------
11201135

0 commit comments

Comments
 (0)