Set logger handler formatters to more detail
548088
def set_verbose_logger_handlers():  # noqa
    # type: (None) -> None
    """"""
    global _REGISTERED_LOGGER_HANDLERS
    formatter = logging.Formatter(
        '%(asctime)s %(levelname)s %(name)s:%(funcName)s:%(lineno)d '
        '%(message)s')
    formatter.default_msec_format = '%s.%03d'
    for handler in _REGISTERED_LOGGER_HANDLERS:
        handler.setFormatter(formatter)
1016210
def _configure_logger_for_production(logger):
    
    stderr_handler = logging.StreamHandler(sys.stderr)
    stderr_handler.setLevel(logging.INFO)
    if 'STDERR' in app.config:
        logger.addHandler(stderr_handler)

    file_handler = logging.handlers.RotatingFileHandler(
        app.config.get('LOG_FILE'), maxBytes=67108864, backupCount=5)
    file_handler.setLevel(logging.INFO)
    if 'LOG_FILE' in app.config:
        logger.addHandler(file_handler)

    mail_handler = logging.handlers.SMTPHandler(
        '127.0.0.1',
        app.config.get('FROM_EMAIL'),
        app.config.get('ADMINS', []),
        'CKAN Service Error')
    mail_handler.setLevel(logging.ERROR)
    if 'FROM_EMAIL' in app.config:
        logger.addHandler(mail_handler)
788629
def _configure_logger_handler(cls, log_dest, log_filename):
        

        if log_dest is None:
            return None

        msg_format = '%(asctime)s-%(name)s-%(message)s'

        if log_dest == 'stderr':
            # Note: sys.stderr is the default stream for StreamHandler
            handler = logging.StreamHandler()
            handler.setFormatter(logging.Formatter(msg_format))
        elif log_dest == 'file':
            if not log_filename:
                raise ValueError("Log filename is required if log destination "
                                 "is 'file'")
            handler = logging.FileHandler(log_filename, encoding="UTF-8")
            handler.setFormatter(logging.Formatter(msg_format))
        else:
            raise ValueError(
                _format("Invalid log destination: {0!A}; Must be one of: "
                        "{1!A}", log_dest, LOG_DESTINATIONS))

        return handler
1231539
def setup_logger(debug, color):
    """"""
    if debug:
        log_level = logging.DEBUG
    else:
        log_level = logging.INFO

    logger = logging.getLogger('exifread')
    stream = Handler(log_level, debug, color)
    logger.addHandler(stream)
    logger.setLevel(log_level)
461928
def _set_logger(logger_name, level=logging.INFO):
        
        log = logging.getLogger(logger_name)
        log.setLevel(level)

        ch = logging.StreamHandler(None)
        ch.setLevel(level)

        formatter = logging.Formatter(DebugFmtString)

        # add formatter to ch
        ch.setFormatter(formatter)

        # add ch to logger
        log.addHandler(ch)
63985
def _add_handler(logger, handler=None, loglevel=None):
    
    handler.setLevel(loglevel or DEFAULT_LOGLEVEL)
    if handler.level <= logging.DEBUG:
        _fmt = '%(asctime)s| %(levelname)-4.3s|%(threadName)10.9s/' \
               '%(lineno)04d@%(module)-10.9s| %(message)s'
        handler.setFormatter(logging.Formatter(_fmt))
    else:
        handler.setFormatter(logging.Formatter(
            '%(asctime)s| %(levelname)-8s| %(message)s'
        ))
    logger.addHandler(handler)
830915
def add_file_handler(logger, logFilename=None):
    
    assert isinstance(logger, logging.Logger)
    ch = logging.FileHandler(logFilename, "a")
    # ch.setFormatter(logging._defaultFormatter) # todo may change to have same formatter as last handler of logger
    ch.setFormatter(_fmtr)
    logger.addHandler(ch)
367111
def setup_logger(logger, stream, filename=None, fmt=None):
    
    if len(logger.handlers) < 1:
        console = logging.StreamHandler(stream)
        console.setLevel(logging.DEBUG)
        console.setFormatter(logging.Formatter(fmt))
        logger.addHandler(console)
        logger.setLevel(logging.DEBUG)
        logger.propagate = False

        if filename:
            outfile = logging.FileHandler(filename)
            outfile.setLevel(logging.INFO)
            outfile.setFormatter(logging.Formatter("%(asctime)s " + (fmt if fmt else '%(message)s')))
            logger.addHandler(outfile)
387499
def set_level_for_logger_and_its_handlers(log: logging.Logger,
                                          level: int) -> None:
    
    log.setLevel(level)
    for h in log.handlers:  # type: logging.Handler
        h.setLevel(level)
1331209
def describe_handler(h):
    """"""
    t = h.__class__  # using type() breaks in Python <= 2.6
    format = handler_formats.get(t)
    if format is not None:
        yield format % h.__dict__
    else:
        yield repr(h)
    level = getattr(h, 'level', logging.NOTSET)
    if level != logging.NOTSET:
        yield '  Level ' + logging.getLevelName(level)
    for f in getattr(h, 'filters', ()):
        yield '  Filter %s' % describe_filter(f)
    formatter = getattr(h, 'formatter', None)
    if formatter is not None:
        if type(formatter) is logging.Formatter:
            yield '  Formatter fmt=%r datefmt=%r' % (
                getattr(formatter, '_fmt', None),
                getattr(formatter, 'datefmt', None))
        else:
            yield '  Formatter %r' % (formatter,)
    if t is logging.handlers.MemoryHandler and h.target is not None:
        yield '  Flushes output to:'
        g = describe_handler(h.target)
        yield '    Handler ' + next(g)
        for line in g:
            yield '    ' + line
1204087
def setup_logging(verbose=False, logger=None):
    
    if not verbose:
        logging.getLogger('requests').setLevel(logging.WARNING)

    format_ = '%(asctime)s %(levelname)-8s %(name)-40s %(message)s' if verbose else '%(message)s'
    level = logging.DEBUG if verbose else logging.INFO

    handler_stdout = logging.StreamHandler(sys.stdout)
    handler_stdout.setFormatter(logging.Formatter(format_))
    handler_stdout.setLevel(logging.DEBUG)
    handler_stdout.addFilter(InfoFilter())

    handler_stderr = logging.StreamHandler(sys.stderr)
    handler_stderr.setFormatter(logging.Formatter(format_))
    handler_stderr.setLevel(logging.WARNING)

    root_logger = logging.getLogger(logger)
    root_logger.setLevel(level)
    root_logger.addHandler(handler_stdout)
    root_logger.addHandler(handler_stderr)
1336048
def colorize_logger(logger, stream=None, level=logging.DEBUG):
    
    logger.handlers = []
    logger.filters = []
    stream = stream or sys.stderr
    handler = logging.StreamHandler(stream=stream)
    handler.setLevel(level)
    handler.setFormatter(Colorful())
    logger.addHandler(handler)
    return logger
232421
def configure_stdout_logger(log_level=logging.DEBUG):
    """"""
    root = logging.getLogger()
    root.setLevel(log_level)

    handler = logging.StreamHandler()
    handler.setLevel(log_level)
    handler.setFormatter(logging.Formatter(LOG_FORMAT_ESCAPED))

    root.addHandler(handler)
659795
def set_logger(self, logger_name, level=logging.INFO):
        
        log = logging.getLogger(logger_name)
        log.setLevel(level)

        ch = logging.StreamHandler(None)
        ch.setLevel(level)

        # create formatter
        if level == logging.INFO:
            formatter = logging.Formatter(InfoFmtString)
        else:
            formatter = logging.Formatter(DebugFmtString)

        # add formatter to ch
        ch.setFormatter(formatter)

        # add ch to logger
        log.addHandler(ch)
524800
def get_basic_logger(level=logging.WARN, scope='reliure'):
    
    logger = logging.getLogger(scope)
    logger.setLevel(level)
    # create console handler with a higher log level
    ch = logging.StreamHandler()
    ch.setLevel(level)
    # create formatter and add it to the handlers
    formatter = ColorFormatter('%(asctime)s:%(levelname)s:%(name)s:%(message)s')
    ch.setFormatter(formatter)
    # add the handlers to the logger
    logger.addHandler(ch)   
    return logger
353836
def setup_logging(config_path=None, log_level=logging.INFO,
                  formatter='standard'):
    

    config = {
        'version': 1,
        'disable_existing_loggers': False,
        'formatters': {
            'standard': {
                'format':
                    '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
            },
            'ui': {
                'format':
                    '[%(levelname)s] %(message)s'
            }
        },
        'handlers': {
            'console': {
                'class': 'logging.StreamHandler',
                'level': log_level,
                'formatter': formatter,
                'stream': 'ext://sys.stdout'
            },
        },
        'loggers': {
            '': {
                'handlers': ['console'],
                'level': log_level,
                'propagate': True
            },
            'yapsy': {
                'handlers': ['console'],
                'level': logging.INFO
            }
        }
    }

    if config_path:
        if os.path.exists(config_path):
            with open(config_path, 'rt') as f:
                config = yaml.safe_load(f.read())
        else:
            print('Specified path does not exist: {}, '
                  'using default config'.format(config_path))

    logging.config.dictConfig(config)
303308
def add_log_handler(log, handler=None, debug=None, fmt=None):
    
    if debug:
        log.setLevel(debug)
    if handler:
        # if not fmt:
        #     fmt = __LOG_FMT
        if fmt:
            handler.setFormatter(fmt)
        log.addHandler(handler)