I have the following complete python (3.8.5) code example
import logging
L = logging.getLogger(__name__)
def main():
L.setLevel(logging.DEBUG)
L.warning("This is warn")
L.info("This is info")
L.debug("This is debug")
if __name__ == "__main__":
main()
which should print out all three phrases, but only prints the first one (for warning).
How to circumvent this bug?
You should switch the L.setLevel to logging.basicConfig(level=...)
e.g.:
def main():
logging.basicConfig(level=logging.DEBUG)
L.warning("This is warn")
L.info("This is info")
L.debug("This is debug")
The method you used, sets the logging level for this logger specifically, meaning the specific logger won't actually do anything when logging on lower leverls - it has nothing to do with the logging level of the process and printing. Using logging.basicConfig you config the process' logging level, so even if you have multiple loggers this level will determine which logging messages come out of the process.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With