openant icon indicating copy to clipboard operation
openant copied to clipboard

Do not print() within Modules

Open daryltucker opened this issue 3 years ago • 0 comments

Allow developers to control what is printed in their applications (and where) by only using a logger within module code.

Even after disabling loggers, I was getting DEBUG information printing to stdout. I tried a lot of things, and got pretty desperate...

loggers = [logging.getLogger(name) for name in logging.root.manager.loggerDict]
for logger in loggers:
    try:
        logger.removeHandler(sys.stderr)
    except Exception:
        pass
    logger.setLevel(0)
    logger.disabled = True
    logger.propagate = False

Then I found print statements in the module.


This uses the existing logger instead of print. There are also some small fixes to technically incorrect Exception statements.

daryltucker avatar Aug 18 '22 00:08 daryltucker