Skip to content

Commit 2176898

Browse files
authored
gh-92859: Doc: add info about logging.debug() calling basicConfig() (GH-93063)
1 parent c1f5c90 commit 2176898

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

Diff for: Doc/howto/logging.rst

+5-4
Original file line numberDiff line numberDiff line change
@@ -178,10 +178,11 @@ following example::
178178
raise ValueError('Invalid log level: %s' % loglevel)
179179
logging.basicConfig(level=numeric_level, ...)
180180

181-
The call to :func:`basicConfig` should come *before* any calls to :func:`debug`,
182-
:func:`info` etc. As it's intended as a one-off simple configuration facility,
183-
only the first call will actually do anything: subsequent calls are effectively
184-
no-ops.
181+
The call to :func:`basicConfig` should come *before* any calls to
182+
:func:`debug`, :func:`info`, etc. Otherwise, those functions will call
183+
:func:`basicConfig` for you with the default options. As it's intended as a
184+
one-off simple configuration facility, only the first call will actually do
185+
anything: subsequent calls are effectively no-ops.
185186

186187
If you run the above script several times, the messages from successive runs
187188
are appended to the file *example.log*. If you want each run to start afresh,

Diff for: Doc/library/logging.rst

+8
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,10 @@ is the module's name in the Python package namespace.
242242
above example). In such circumstances, it is likely that specialized
243243
:class:`Formatter`\ s would be used with particular :class:`Handler`\ s.
244244

245+
If no handler is attached to this logger (or any of its ancestors,
246+
taking into account the relevant :attr:`Logger.propagate` attributes),
247+
the message will be sent to the handler set on :attr:`lastResort`.
248+
245249
.. versionchanged:: 3.2
246250
The *stack_info* parameter was added.
247251

@@ -1038,6 +1042,10 @@ functions.
10381042
above example). In such circumstances, it is likely that specialized
10391043
:class:`Formatter`\ s would be used with particular :class:`Handler`\ s.
10401044

1045+
This function (as well as :func:`info`, :func:`warning`, :func:`error` and
1046+
:func:`critical`) will call :func:`basicConfig` if the root logger doesn't
1047+
have any handler attached.
1048+
10411049
.. versionchanged:: 3.2
10421050
The *stack_info* parameter was added.
10431051

0 commit comments

Comments
 (0)