我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用logging._checkLevel()。
def _checkLevel(level): if isinstance(level, int): rv = level elif str(level) == level: if level not in logging._levelNames: raise ValueError('Unknown level: %r' % level) rv = logging._levelNames[level] else: raise TypeError('Level not an integer or a ' 'valid string: %r' % level) return rv # The ConvertingXXX classes are wrappers around standard Python containers, # and they serve to convert any suitable values in the container. The # conversion converts base dicts, lists and tuples to their wrapped # equivalents, whereas strings which match a conversion format are converted # appropriately. # # Each wrapper should have a configurator attribute holding the actual # configurator to use for conversion.
def common_logger_config(self, logger, config, incremental=False): """ Perform configuration which is common to root and non-root loggers. """ level = config.get('level', None) if level is not None: logger.setLevel(_checkLevel(level)) if not incremental: # Remove any existing handlers for h in logger.handlers[:]: logger.removeHandler(h) handlers = config.get('handlers', None) if handlers: self.add_handlers(logger, handlers) filters = config.get('filters', None) if filters: self.add_filters(logger, filters)
def common_logger_config(self, logger, config, incremental=False): """ Perform configuration which is common to root and non-root loggers. """ level = config.get('level', None) if level is not None: logger.setLevel(logging._checkLevel(level)) if not incremental: #Remove any existing handlers for h in logger.handlers[:]: logger.removeHandler(h) handlers = config.get('handlers', None) if handlers: self.add_handlers(logger, handlers) filters = config.get('filters', None) if filters: self.add_filters(logger, filters)
def __init__(self, fmt=None, datefmt=None, style="%"): if style != '%': raise ValueError( "only '%' percent style is supported in both python 2 and 3") if fmt is None: fmt = DEFAULT_FORMATS if isinstance(fmt, basestring): default_format = fmt custom_formats = {} elif isinstance(fmt, collections.Mapping): custom_formats = dict(fmt) default_format = custom_formats.pop("*", None) else: raise TypeError('fmt must be a str or a dict of str: %r' % fmt) super(LevelFormatter, self).__init__(default_format, datefmt) self.default_format = self._fmt self.custom_formats = {} for level, fmt in custom_formats.items(): level = logging._checkLevel(level) self.custom_formats[level] = fmt