Skip to content

Commit d0ce087

Browse files
committed
Doc: add info about logging.debug() calling basicConfig()
This adds some info about logging.debug() (and other level functions) calling basicConfig() on behalf of the user if logging wasn't configured beforehand.
1 parent e5d8dbd commit d0ce087

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

Doc/howto/logging.rst

Lines changed: 5 additions & 4 deletions
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,

Doc/library/logging.rst

Lines changed: 7 additions & 0 deletions
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 its parents if
246+
:attr:`Logger.propagate` evaluates to true), the message will be sent to
247+
the handler set on :attr:`lastResort`.
248+
245249
.. versionchanged:: 3.2
246250
The *stack_info* parameter was added.
247251

@@ -1038,6 +1042,9 @@ 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+
The function will call :func:`basicConfig` if the root logger doesn't have
1046+
any handler attached.
1047+
10411048
.. versionchanged:: 3.2
10421049
The *stack_info* parameter was added.
10431050

0 commit comments

Comments
 (0)