I want to turn on debug output for one run without editing the script.
import logging, os
logging.basicConfig(
level=os.environ.get("LOGLEVEL", "INFO").upper(),
format="%(asctime)s %(levelname)s %(name)s: %(message)s")
Run LOGLEVEL=DEBUG python3 app.py to see debug messages and nothing changes for normal runs. basicConfig accepts the level as a string, and the format adds a timestamp and the logger name. It does nothing if the root logger already has handlers, unless you pass force=True (Python 3.8 and later). Call it once, early, in your entry point and not inside library modules. Keep the format string in one place so every module logs the same way.
Further reading: logging documentation