Skip to content

gh-92859: Doc: add info about logging.debug() calling basicConfig() (GH-93063) #93063

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions Doc/howto/logging.rst
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,11 @@ following example::
raise ValueError('Invalid log level: %s' % loglevel)
logging.basicConfig(level=numeric_level, ...)

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

If you run the above script several times, the messages from successive runs
are appended to the file *example.log*. If you want each run to start afresh,
Expand Down
8 changes: 8 additions & 0 deletions Doc/library/logging.rst
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,10 @@ is the module's name in the Python package namespace.
above example). In such circumstances, it is likely that specialized
:class:`Formatter`\ s would be used with particular :class:`Handler`\ s.

If no handler is attached to this logger (or any of its ancestors,
taking into account the relevant :attr:`Logger.propagate` attributes),
the message will be sent to the handler set on :attr:`lastResort`.

.. versionchanged:: 3.2
The *stack_info* parameter was added.

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

This function (as well as :func:`info`, :func:`warning`, :func:`error` and
:func:`critical`) will call :func:`basicConfig` if the root logger doesn't
have any handler attached.

.. versionchanged:: 3.2
The *stack_info* parameter was added.

Expand Down