the root logger for the whole toplevel package logger propagate false handler setformatterlogging formatter in case the provided logger is in a subpackage ignore errors while emitting log entries rather than printing a message describing the error we show nothing for now we simply ignore all exceptions if we wanted to ignore specific ones e g brokenpipeerror then we would need to use a handler subclass with a custom handleerror method the root logger for the whole top level package 0 disables it so we use the next lowest logger propagate false handler setformatter logging formatter in case the provided logger is in a sub package ignore errors while emitting log entries rather than printing a message describing the error we show nothing for now we simply ignore all exceptions if we wanted to ignore specific ones e g brokenpipeerror then we would need to use a handler subclass with a custom handleerror method
import logging
import sys


VERBOSITY = 3



_logger = logging.getLogger(__name__.rpartition('.')[0])


def configure_logger(logger, verbosity=VERBOSITY, *,
                     logfile=None,
                     maxlevel=logging.CRITICAL,
                     ):
    level = max(1,  
                min(maxlevel,
                    maxlevel - verbosity * 10))
    logger.setLevel(level)
    

    if not logger.handlers:
        if logfile:
            handler = logging.FileHandler(logfile)
        else:
            handler = logging.StreamHandler(sys.stdout)
        handler.setLevel(level)
        
        logger.addHandler(handler)

    
    if logger is not _logger:
        configure_logger(
            _logger,
            verbosity,
            logfile=logfile,
            maxlevel=maxlevel,
        )


def hide_emit_errors():
    
    
    
    
    orig = logging.raiseExceptions
    logging.raiseExceptions = False
    def restore():
        logging.raiseExceptions = orig
    return restore


class Printer:
    def __init__(self, verbosity=VERBOSITY):
        self.verbosity = verbosity

    def info(self, *args, **kwargs):
        if self.verbosity < 3:
            return
        print(*args, **kwargs)