Format the log record to include exc_info if the handler is enabled for a specific log level
971728
def format(self, record):
        '''
        
        '''
        formatted_record = super(ExcInfoOnLogLevelFormatMixIn, self).format(record)
        exc_info_on_loglevel = getattr(record, 'exc_info_on_loglevel', None)
        exc_info_on_loglevel_formatted = getattr(record, 'exc_info_on_loglevel_formatted', None)
        if exc_info_on_loglevel is None and exc_info_on_loglevel_formatted is None:
            return formatted_record

        # If we reached this far it means the log record was created with exc_info_on_loglevel
        # If this specific handler is enabled for that record, then we should format it to
        # include the exc_info details
        if self.level > exc_info_on_loglevel:
            # This handler is not enabled for the desired exc_info_on_loglevel, don't include exc_info
            return formatted_record

        # If we reached this far it means we should include exc_info
        if not record.exc_info_on_loglevel_instance and not exc_info_on_loglevel_formatted:
            # This should actually never occur
            return formatted_record

        if record.exc_info_on_loglevel_formatted is None:
            # Let's cache the formatted exception to avoid recurring conversions and formatting calls
            if self.formatter is None:  # pylint: disable=access-member-before-definition
                self.formatter = logging._defaultFormatter
            record.exc_info_on_loglevel_formatted = self.formatter.formatException(
                record.exc_info_on_loglevel_instance
            )

        # Let's format the record to include exc_info just like python's logging formatted does
        if formatted_record[-1:] != '\n':
            formatted_record += '\n'

        try:
            formatted_record += record.exc_info_on_loglevel_formatted
        except UnicodeError:
            # According to the standard library logging formatter comments:
            #
            #     Sometimes filenames have non-ASCII chars, which can lead
            #     to errors when s is Unicode and record.exc_text is str
            #     See issue 8924.
            #     We also use replace for when there are multiple
            #     encodings, e.g. UTF-8 for the filesystem and latin-1
            #     for a script. See issue 13232.
            formatted_record += record.exc_info_on_loglevel_formatted.decode(sys.getfilesystemencoding(),
                                                                             'replace')
        # Reset the record.exc_info_on_loglevel_instance because it might need
        # to "travel" through a multiprocessing process and it might contain
        # data which is not pickle'able
        record.exc_info_on_loglevel_instance = None
        return formatted_record
1159183
def enable_logging( level='WARNING' ):
    
    log = logging.getLogger( 'mrcrowbar' )
    log.setLevel( level )
    out = logging.StreamHandler()
    out.setLevel( level )
    form = logging.Formatter( '[%(levelname)s] %(name)s - %(message)s' )
    out.setFormatter( form )
    log.addHandler( out )
256880
def show_logging(level=logging.INFO):
    
    logger = logging.getLogger()

    h = logging.StreamHandler(stream=sys.stderr)
    h.setFormatter(logging.Formatter(fmt="[%(levelname)-8s] %(name)s: %(message)s"))

    logger.addHandler(h)
    logger.setLevel(level)
1218297
def set_logging_config(log_level, handlers):
    
    logging.basicConfig(
        format='%(asctime)s %(levelname)s:%(name)s:%(funcName)s: %(message)s',
        datefmt='%Y-%m-%d %H:%M:%S',
        level=log_level,
        handlers=handlers)
923460
def logToConsole(level=logging.INFO):
    
    logger = logging.getLogger()
    logger.setLevel(level)
    formatter = logging.Formatter(
        '%(asctime)s %(name)s %(levelname)s %(message)s')
    handler = logging.StreamHandler()
    handler.setFormatter(formatter)
    logger.handlers = [
        h for h in logger.handlers
        if type(h) is not logging.StreamHandler]
    logger.addHandler(handler)
719565
def setup_logging(level, logger_name=None, handler=None, log_formatter=None):
    
    root_logger = logging.getLogger()

    if logger_name is None:
        logger = root_logger
        root_logger.info("Set %i level to root logger", level)
    else:
        logger = logging.getLogger(logger_name)
        root_logger.info("Set %i level to logger %r", level, logger_name)

    if level == 100:
        # Remove all existing handlers and set only NullHandler():
        set_handler(logger, logging.NullHandler())
        logger.disabled = True
        return

    logger.setLevel(level=level)

    if log_formatter is None:
        log_formatter = "%(relativeCreated)-5d %(levelname)8s %(module)13s %(lineno)d %(message)s"
    formatter = logging.Formatter(log_formatter)

    if handler is None:
        handler = logging.StreamHandler()
    handler.setFormatter(formatter)

    if hasattr(handler, "baseFilename"):
        root_logger.debug("Log to file: %s (%s)", handler.baseFilename, repr(handler))
    else:
        root_logger.debug("Log to handler: %s", repr(handler))

    # Remove all existing handlers and set only the given handler:
    set_handler(logger, handler)

    log.log(level, "Set logging to level %i %s", level, logging.getLevelName(level))
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
1215896
def handle_logging(self):
        

        configure_logging(self.get_scrapy_options())

        # Disable duplicates
        self.__scrapy_options["LOG_ENABLED"] = False

        # Now, after log-level is correctly set, lets log them.
        for msg in self.log_output:
            if msg["level"] is "error":
                self.log.error(msg["msg"])
            elif msg["level"] is "info":
                self.log.info(msg["msg"])
            elif msg["level"] is "debug":
                self.log.debug(msg["msg"])
777577
public void log(LogRecord record) {
        if (record.getLevel().intValue() < levelValue || levelValue == offValue) {
            return;
        }
        Filter theFilter = filter;
        if (theFilter != null && !theFilter.isLoggable(record)) {
            return;
        }

        // Post the LogRecord to all our Handlers, and then to
        // our parents' handlers, all the way up the tree.

        Logger logger = this;
        while (logger != null) {
            for (Handler handler : logger.getHandlers()) {
                handler.publish(record);
            }

            if (!logger.getUseParentHandlers()) {
                break;
            }

            logger = logger.getParent();
        }
    }
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)
150462
def log(self, level, prefix = ''):
        
        logging.log(level, "%sname: %s", prefix, self.__name)
        logging.log(level, "%soptions: %s", prefix, self.__options)
270383
def enable_logging(log_level):
    # type: (typing.Union[None, int]) -> None
    
    root_logger = logging.getLogger()
    root_logger.setLevel(logging.DEBUG)
    logfile_handler = logging.StreamHandler(_LOGFILE_STREAM)
    logfile_handler.setLevel(logging.DEBUG)
    logfile_handler.setFormatter(logging.Formatter(
        '%(levelname)s [%(asctime)s][%(name)s] %(message)s'))
    root_logger.addHandler(logfile_handler)
    if signal.getsignal(signal.SIGTERM) == signal.SIG_DFL:
        signal.signal(signal.SIGTERM, _logfile_sigterm_handler)
    if log_level:
        handler = logging.StreamHandler()
        handler.setFormatter(_LogColorFormatter())
        root_logger.setLevel(log_level)
        root_logger.addHandler(handler)
1004234
def get_handler_report(h: logging.Handler) -> Dict[str, Any]:
    
    return {
        'get_name()': h.get_name(),
        'level': h.level,
        'formatter': get_formatter_report(h.formatter),
        'filters': h.filters,
    }
1317329
def emit(self, record):
        
        try:
            msg = self.format(record)
            level = _STORM_LOG_LEVELS.get(record.levelname.lower(), _STORM_LOG_INFO)
            self.serializer.send_message(
                {"command": "log", "msg": str(msg), "level": level}
            )
        except Exception:
            self.handleError(record)
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)
1082108
def _log(self,
             level,
             fmt,
             args=None,
             extra=None,
             exc_info=None,
             inc_stackinfo=False,
             inc_multiproc=False):
        
        if not self.enabled:
            return # Fail silently so that logging can easily be removed

        log_record = self._make_record(
          level, fmt, args, extra, exc_info, inc_stackinfo, inc_multiproc)

        logstr = log_record['defaultfmt'].format(**log_record) #whoah.

        if self.keep_history:
            self.history.append(logstr)

        log_funcs = self.config[level]
        to_remove = []
        for lf in log_funcs:
            try:
                lf.send(logstr)
            except StopIteration:
                # in the case that the log function is already closed, add it
                # to the list of functions to be deleted.
                to_remove.append(lf)
        for lf in to_remove:
            self.remove(level, lf)
            self.info('Logging function {} removed from level {}', lf, level)
768299
def set_log_level(self, level=logging.INFO):
        
        mod, cls = self.parse_module_class()
        logging.getLogger(mod).setLevel(level)