Notes on Python

Posted on November 11, 2019 | python

Setting log level dynamically #

If you want to change the log level for one iteration of a loop or one call of a function, it can be done by calling setLevel on the current logger instance.

import logging

logging.error("This statement will be shown")

logging.debug("This will not be shown")


logging.debug("This debug statement will be shown")


logging.debug("This debug statement will be hidden")

This results in

ERROR:root:This statement will be shown
DEBUG:root:This debug statement will be shown
  1. Logging module documentation -
  2. Logging HOWTO -