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

Skip to content

Commit e50f4d2

Browse files
committed
Issue #16884: updated logging documentation to include lastResort and use 'note' directives where appropriate.
1 parent a4e700c commit e50f4d2

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
@@ -928,14 +928,14 @@ functions.
928928
Logs a message with level *level* on the root logger. The other arguments are
929929
interpreted as for :func:`debug`.
930930

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

940940
.. function:: disable(lvl)
941941

@@ -991,12 +991,12 @@ functions.
991991
This function does nothing if the root logger already has handlers
992992
configured for it.
993993

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

10011001
The following keyword arguments are supported.
10021002

@@ -1080,6 +1080,21 @@ functions.
10801080
:kwargs: Additional keyword arguments.
10811081

10821082

1083+
Module-Level Attributes
1084+
-----------------------
1085+
1086+
.. attribute:: lastResort
1087+
1088+
A "handler of last resort" is available through this attribute. This
1089+
is a :class:`StreamHandler` writing to ``sys.stderr`` with a level of
1090+
``WARNING``, and is used to handle logging events in the absence of any
1091+
logging configuration. The end result is to just print the message to
1092+
``sys.stderr``. This replaces the earlier error message saying that
1093+
"no handlers could be found for logger XYZ". If you need the earlier
1094+
behaviour for some reason, ``lastResort`` can be set to ``None``.
1095+
1096+
.. versionadded:: 3.2
1097+
10831098
Integration with the warnings module
10841099
------------------------------------
10851100

0 commit comments

Comments
 (0)