pythonlogging

Suppressing Logging From Package/Module when `logging` is used directly


I am using the pdf2docx package Gitub in python and it looks like in the converter module, they use logging directly instead of using a logger like

logger = logger.getLogger(__name__)

The logging.basicConfig in converter is set to logging.INFO and is propagating these horrible logs on. Is it impossible to suppress them because they use logging directly?


Solution

  • Create a default catchall root logger object and tell it to be silent:

    rootLogger = logging.getLogger("")
    rootLogger.disabled = True
    rootLogger.propagate = False
    

    Direct calls to logging will inherit these settings.