This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: logging does not work as documented (setLevel)
Type: behavior Stage: resolved
Components: Documentation Versions: Python 3.8
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: docs@python Nosy List: alex4200, cryvate, docs@python, vinay.sajip
Priority: normal Keywords:

Created on 2021-06-17 10:10 by alex4200, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
problem.py alex4200, 2021-06-17 10:10 Example code
Messages (5)
msg395984 - (view) Author: Alexander Dietz (alex4200) Date: 2021-06-17 10:10
Using python 3.8.10 and the documentation https://docs.python.org/3.8/library/logging.html it seems that either the documentation is incorrect/unclear, or that the logging module does not work as described. 

Reading on the Logger Object and the setLevel method I created the attached python code, which does not work as expected. As I set the level to "DEBUG", and the documentation clearly says " Logging messages which are less severe than level will be ignored". But having set the level to DEBUG, even the more "severe" info message is ignored. That is clearly contradicting the documentation!
msg395987 - (view) Author: Henk-Jaap Wagenaar (cryvate) * Date: 2021-06-17 10:19
Logging can be quite tricky. There are filters at multiple levels. In this case, you didn't set up the "global logging" and I am guessing, by default, it only shows WARNING and above. You can fix your problem by doing:

logging.basicConfig(level=logging.DEBUG)
msg395993 - (view) Author: Alexander Dietz (alex4200) Date: 2021-06-17 11:05
I was not asking for a solution or a workaround. I simply wanted to submit this bug in either the code or the documentation.
msg395998 - (view) Author: Henk-Jaap Wagenaar (cryvate) * Date: 2021-06-17 12:09
The sentence within the doc should not be considered in isolation.

The "Logger" object is *not* ignoring the message (in accordance with the documentation and your expectation), but the "Handler" is, see https://docs.python.org/3.8/library/logging.html#logging.Handler.setLevel and here: https://docs.python.org/3/howto/logging.html: "The default level is WARNING, which means that only events of this level and above will be tracked, unless the logging package is configured to do otherwise."

Logging is quite complicated, and reading the API reference is not the best starting point, as is noted at the top of the page and links provided.
msg396705 - (view) Author: Vinay Sajip (vinay.sajip) * (Python committer) Date: 2021-06-29 08:17
As Henk-Jaap points out, this is not a bug. You can't take a single sentence or even paragraph without considering the whole picture. In particular, this section

https://docs.python.org/3/howto/logging.html#what-happens-if-no-configuration-is-provided

explains clearly why the behaviour you noticed is as expected. Another section even depicts it pictorially:

https://docs.python.org/3/howto/logging.html#logging-flow
History
Date User Action Args
2022-04-11 14:59:46adminsetgithub: 88606
2021-06-29 08:17:36vinay.sajipsetstatus: open -> closed
resolution: not a bug
messages: + msg396705

stage: resolved
2021-06-29 03:45:28ned.deilysetnosy: + vinay.sajip
2021-06-17 12:09:05cryvatesetmessages: + msg395998
2021-06-17 11:05:05alex4200setmessages: + msg395993
2021-06-17 10:19:39cryvatesetnosy: + cryvate
messages: + msg395987
2021-06-17 10:10:19alex4200create