Returns information on a log formatter, as a dictionary.
    For debugging.
979826
def get_formatter_report(f: logging.Formatter) -> Optional[Dict[str, str]]:
    
    if f is None:
        return None
    return {
        '_fmt': f._fmt,
        'datefmt': f.datefmt,
        '_style': str(f._style),
    }
198810
def get_formatter(name):
    
    if name in ('self', 'instance', 'this'):
        return af_self
    elif name == 'class':
        return af_class
    elif name in ('named', 'param', 'parameter'):
        return af_named
    elif name in ('default', 'optional'):
        return af_default
#    elif name in ('anonymous', 'arbitrary', 'unnamed'):
#        return af_anonymous
    elif name in ('keyword', 'pair', 'pairs'):
        return af_keyword
    else:
        raise ValueError('unknown trace formatter %r' % name)
660269
def as_dictionary(self):
        
        return {
            "name": self.name,
            "type": self.type,
            "value": remove_0x_prefix(self.value) if self.type == 'bytes32' else self.value
        }
658684
def get_logger(name=None, format_string=None):
    
    logging.captureWarnings(True)
    log = logging.getLogger(name)

    # Bind custom method to instance.
    # Source: https://stackoverflow.com/a/2982
    log.set_debug_level = _set_debug_level.__get__(log)
    log.set_debug_level(0)

    if not format_string:
        format_string = '[%(module)s]\t%(levelname)s\t%(message)s'

    # Setting up log formats
    log.handlers = []
    handler = logging.StreamHandler(sys.stderr)
    handler.setFormatter(
        logging.Formatter(format_string),
    )
    log.addHandler(handler)

    return log
1312573
def print_dict(dict_name, dict_value, logger: Logger = None):
    
    if logger is None:
        print(dict_name + ' = ')
        try:
            from pprint import pprint
            pprint(dict_value)
        except:
            print(dict_value)
    else:
        logger.info(dict_name + ' = ')
        try:
            from pprint import pformat
            logger.info(pformat(dict_value))
        except:
            logger.info(dict_value)
1319510
def dict(self):
        
        params = {
            prop: getattr(self, prop)
            for prop in [
                "logs", "date", "author", "sha", "path"
            ]
        }
        params["author"] = params["author"].dict()
        return params
908503
def info(self):
        
        return {
            'key': self.key,
            'processor': self.processor,
            'extractor': self.extractor,
            'output_path': self.output_path,
            'output_format': self.output_format,
            'template': self.template,
            'type': type(self)
        }
772171
def info(self, msg=None, *args, **kwargs):
        """"""

        return self._log(logging.INFO, msg, args, kwargs)
1119821
def log(self):
        '''
        
        '''

        log = self._log(num=10, format='%h::%b').get('stdout')
        if log:
            return [
                dict(commit=c, message=m) for c, m in [
                    l.split('::') for l in log
                ]
            ]
638578
def dump_to_log(self):
        
        if self._event_dict:
            logger.info('Events:')
            for event_str, count_int in sorted(self._event_dict.items()):
                logger.info('  {}: {}'.format(event_str, count_int))
        else:
            logger.info('No Events')
54350
def _to_dict(self):
        """"""
        _dict = {}
        if hasattr(self, 'debug') and self.debug is not None:
            _dict['debug'] = self.debug
        if hasattr(self, 'restart') and self.restart is not None:
            _dict['restart'] = self.restart
        if hasattr(self,
                   'alternate_intents') and self.alternate_intents is not None:
            _dict['alternate_intents'] = self.alternate_intents
        if hasattr(self, 'return_context') and self.return_context is not None:
            _dict['return_context'] = self.return_context
        return _dict
759034
def log_config(log_level: Union[str, int]) -> dict:
    
    if isinstance(log_level, int):
        # to match django
        log_level = {3: 'DEBUG', 2: 'INFO'}.get(log_level, 'WARNING')
    assert log_level in {'DEBUG', 'INFO', 'WARNING', 'ERROR'}, 'wrong log level %s' % log_level
    return {
        'version': 1,
        'disable_existing_loggers': True,
        'formatters': {
            'default': {'format': '%(message)s'},
            'indent': {'format': '    %(message)s'},
        },
        'handlers': {
            'default': {
                'level': log_level,
                'class': 'grablib.common.ClickHandler',
                'formatter': 'default'
            },
            'progress': {
                'level': log_level,
                'class': 'grablib.common.ProgressHandler',
                'formatter': 'indent'
            },
        },
        'loggers': {
            main_logger.name: {
                'handlers': ['default'],
                'level': log_level,
                'propagate': False,
            },
            progress_logger.name: {
                'handlers': ['progress'],
                'level': log_level,
                'propagate': False,
            },
        },
    }
1267593
def _logger(self):
        
        log_level = {
            'debug': logging.DEBUG,
            'info': logging.INFO,
            'warning': logging.WARNING,
            'error': logging.ERROR,
            'critical': logging.CRITICAL,
        }
        level = log_level.get(self.args.logging_level.lower())

        # Formatter
        tx_format = '%(asctime)s - %(name)s - %(levelname)s - %(message)s '
        tx_format += '(%(funcName)s:%(lineno)d)'
        formatter = logging.Formatter(tx_format)

        # Logger
        log = logging.getLogger('tcrun')

        # # Stream Handler
        # sh = logging.StreamHandler()
        # sh.set_name('sh')
        # sh.setLevel(level)
        # sh.setFormatter(formatter)
        # log.addHandler(sh)

        # File Handler
        if not os.access('log', os.W_OK):
            os.makedirs('log')
        logfile = os.path.join('log', 'run.log')
        fh = logging.FileHandler(logfile)
        fh.set_name('fh')
        fh.setLevel(logging.DEBUG)
        fh.setFormatter(formatter)
        log.addHandler(fh)

        log.setLevel(level)
        log.info('Logging Level: {}'.format(logging.getLevelName(level)))
        return log
1112840
def to_api_repr(self):
        
        info = {}
        if self.log_name is not None:
            info["logName"] = self.log_name
        if self.resource is not None:
            info["resource"] = self.resource._to_dict()
        if self.labels is not None:
            info["labels"] = self.labels
        if self.insert_id is not None:
            info["insertId"] = self.insert_id
        if self.severity is not None:
            info["severity"] = self.severity
        if self.http_request is not None:
            info["httpRequest"] = self.http_request
        if self.timestamp is not None:
            info["timestamp"] = _datetime_to_rfc3339(self.timestamp)
        if self.trace is not None:
            info["trace"] = self.trace
        if self.span_id is not None:
            info["spanId"] = self.span_id
        if self.trace_sampled is not None:
            info["traceSampled"] = self.trace_sampled
        if self.source_location is not None:
            source_location = self.source_location.copy()
            source_location["line"] = str(source_location.pop("line", 0))
            info["sourceLocation"] = source_location
        if self.operation is not None:
            info["operation"] = self.operation
        return info
541708
def get_loglevel(level):
    
    try:
        return [logging.DEBUG, logging.INFO, logging.WARN][level]
    except IndexError:
        return logging.INFO
574630
def get_formatter(self):
        
        if not self.fmt:
            self.fmt = ('%(asctime)s.%(msecs)03d {host} {progname} '
                        '(%(process)d): %(message)s').format(
                        host=self.hostname, progname=self.progname)
        if not self.datefmt:
            self.datefmt = '%Y-%m-%dT%H:%M:%S'
        return logging.Formatter(fmt=self.fmt, datefmt=self.datefmt)
747376
def dump(self):
        

        # Print out the collectd feedback.
        # This is sent to stdout while other log messages are sent to stderr.
        for k, v in sorted(self._dict.items()):
            print(self.formatter(k, v))

        # Reset each entry to zero
        for k, v in sorted(self._dict.items()):
            self._dict[k] = 0