当前位置: 首页>>代码示例>>Python>>正文


Python logging.addLevelName方法代码示例

本文整理汇总了Python中logging.addLevelName方法的典型用法代码示例。如果您正苦于以下问题:Python logging.addLevelName方法的具体用法?Python logging.addLevelName怎么用?Python logging.addLevelName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在logging的用法示例。


在下文中一共展示了logging.addLevelName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __call__

# 需要导入模块: import logging [as 别名]
# 或者: from logging import addLevelName [as 别名]
def __call__(self, customlevel):
        """
        Wrap the decorated function to take care of the setting up of the custom log level.

        """
        # Add the new custom level to the list of known levels
        logging.addLevelName(self.level, self.name)

        def _wrapper(msg, *args, **kwargs):
            # Check if the currently set level allows this log level to print.
            if self.logger.isEnabledFor(level):
                _msg, _args, _kwargs = customlevel(self.logger, msg, *args, **kwargs)
                self.logger.log(level, _msg, *_args, **_kwargs)

        # Create function bindings in the logger or if using the root logger, setup the bindings to allow
        # calls to logging.mycustomlevel() much like logging.info(), logging.debug() etc.
        setattr(self.logger, self.name.lower(), _wrapper)
        if self.logger_name is None:
            setattr(logging, self.name.lower(), _wrapper)

        return customlevel 
开发者ID:lobocv,项目名称:pyperform,代码行数:23,代码来源:customlogger.py

示例2: _configure_logging

# 需要导入模块: import logging [as 别名]
# 或者: from logging import addLevelName [as 别名]
def _configure_logging(options):
    logging.addLevelName(common.LOGLEVEL_FINE, 'FINE')

    logger = logging.getLogger()
    logger.setLevel(logging.getLevelName(options.log_level.upper()))
    if options.log_file:
        handler = logging.handlers.RotatingFileHandler(
                options.log_file, 'a', options.log_max, options.log_count)
    else:
        handler = logging.StreamHandler()
    formatter = logging.Formatter(
            '[%(asctime)s] [%(levelname)s] %(name)s: %(message)s')
    handler.setFormatter(formatter)
    logger.addHandler(handler)

    deflate_log_level_name = logging.getLevelName(
        options.deflate_log_level.upper())
    _get_logger_from_class(util._Deflater).setLevel(
        deflate_log_level_name)
    _get_logger_from_class(util._Inflater).setLevel(
        deflate_log_level_name) 
开发者ID:googlearchive,项目名称:pywebsocket,代码行数:23,代码来源:standalone.py

示例3: _add_logger_level

# 需要导入模块: import logging [as 别名]
# 或者: from logging import addLevelName [as 别名]
def _add_logger_level(levelname, level, *, func_name = None):
    """

    :type levelname: str
        The reference name of the level, e.g. DEBUG, WARNING, etc
    :type level: int
        Numeric logging level
    :type func_name: str
        The name of the logger function to log to a level, e.g. "info" for log.info(...)
    """

    func_name = func_name or levelname.lower()

    setattr(logging, levelname, level)
    logging.addLevelName(level, levelname)

    exec(_func_prototype.format(logger_func_name=func_name, levelname=levelname), logging.__dict__, locals())
    setattr(logging.Logger, func_name, eval(func_name)) 
开发者ID:helionmusic,项目名称:rhinobot_heroku,代码行数:20,代码来源:__init__.py

示例4: initialize_logging

# 需要导入模块: import logging [as 别名]
# 或者: from logging import addLevelName [as 别名]
def initialize_logging(loglevel):
    """Setup basic logging functionality before configfiles have been loaded"""
    # convert levelnames to lowercase
    for level in (10, 20, 30, 40, 50):
        name = logging.getLevelName(level)
        logging.addLevelName(level, name.lower())

    # register custom Logging class
    logging.Logger.manager.setLoggerClass(Logger)

    # setup basic logging to stderr
    formatter = Formatter(LOG_FORMAT, LOG_FORMAT_DATE)
    handler = logging.StreamHandler()
    handler.setFormatter(formatter)
    handler.setLevel(loglevel)
    root = logging.getLogger()
    root.setLevel(logging.NOTSET)
    root.addHandler(handler)

    return logging.getLogger("gallery-dl") 
开发者ID:mikf,项目名称:gallery-dl,代码行数:22,代码来源:output.py

示例5: _configure_logging

# 需要导入模块: import logging [as 别名]
# 或者: from logging import addLevelName [as 别名]
def _configure_logging(level=logging.INFO):
    logging.addLevelName(logging.DEBUG, 'Debug:')
    logging.addLevelName(logging.INFO, 'Info:')
    logging.addLevelName(logging.WARNING, 'Warning!')
    logging.addLevelName(logging.CRITICAL, 'Critical!')
    logging.addLevelName(logging.ERROR, 'Error!')

    logging.basicConfig(format='%(levelname)s %(message)s', level=logging.INFO)

    if not sys.warnoptions:
        import warnings
        warnings.simplefilter("ignore")
        # TODO hack to get rid of deprecation warning that appeared allthough filters
        # are set to ignore. Is there a more sane way?
        warnings.warn = lambda *args, **kwargs: None 
开发者ID:mme,项目名称:vergeml,代码行数:17,代码来源:__main__.py

示例6: get_logger

# 需要导入模块: import logging [as 别名]
# 或者: from logging import addLevelName [as 别名]
def get_logger():
    '''
    Returns logger used by multiprocessing
    '''
    global _logger
    import logging

    logging._acquireLock()
    try:
        if not _logger:

            _logger = logging.getLogger(LOGGER_NAME)
            _logger.propagate = 0
            logging.addLevelName(SUBDEBUG, 'SUBDEBUG')
            logging.addLevelName(SUBWARNING, 'SUBWARNING')

            # XXX multiprocessing should cleanup before logging
            if hasattr(atexit, 'unregister'):
                atexit.unregister(_exit_function)
                atexit.register(_exit_function)
            else:
                atexit._exithandlers.remove((_exit_function, (), {}))
                atexit._exithandlers.append((_exit_function, (), {}))

    finally:
        logging._releaseLock()

    return _logger 
开发者ID:war-and-code,项目名称:jawfish,代码行数:30,代码来源:util.py

示例7: main

# 需要导入模块: import logging [as 别名]
# 或者: from logging import addLevelName [as 别名]
def main(ctx: click.Context, debug: bool, version: bool) -> None:
    """Safe Python code modification and refactoring."""
    if version:
        from bowler import __version__

        click.echo(f"bowler {__version__}")
        return

    if debug:
        BowlerTool.NUM_PROCESSES = 1
        BowlerTool.IN_PROCESS = True

    root = logging.getLogger()
    if not root.hasHandlers():
        logging.addLevelName(logging.DEBUG, "DBG")
        logging.addLevelName(logging.INFO, "INF")
        logging.addLevelName(logging.WARNING, "WRN")
        logging.addLevelName(logging.ERROR, "ERR")
        level = logging.DEBUG if debug else logging.WARNING
        fmt = logging.Formatter("{levelname}:{filename}:{lineno}  {message}", style="{")
        han = logging.StreamHandler(stream=sys.stderr)
        han.setFormatter(fmt)
        han.setLevel(level)
        root.setLevel(level)
        root.addHandler(han)

    if ctx.invoked_subcommand is None:
        return do(None, None) 
开发者ID:facebookincubator,项目名称:Bowler,代码行数:30,代码来源:main.py

示例8: __init__

# 需要导入模块: import logging [as 别名]
# 或者: from logging import addLevelName [as 别名]
def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        logging.addLevelName(VULN_LEVEL.DEBUG, '[~]')
        logging.addLevelName(VULN_LEVEL.WARNING, '[!]')
        logging.addLevelName(VULN_LEVEL.ERROR, '[-]')
        logging.addLevelName(VULN_LEVEL.INFO, '[*]')
        logging.addLevelName(VULN_LEVEL.SUCCESS, '[+]') 
开发者ID:m4yfly,项目名称:butian-src-domains,代码行数:9,代码来源:logger.py

示例9: init_logging

# 需要导入模块: import logging [as 别名]
# 或者: from logging import addLevelName [as 别名]
def init_logging(level: str, package_name: str):
    level = level.upper()
    logging.addLevelName(TRACE, 'TRACE')
    log_colors = dict(colorlog.default_log_colors, **dict(TRACE='cyan'))

    # formatter and handler
    formatter = colorlog.ColoredFormatter(
        log_colors=log_colors,
        fmt='%(asctime)s %(log_color)s%(levelname)-8s%(reset)s'
            ' %(cyan)s{%(threadName)s} %(blue)s[%(name)s]%(reset)s %(message)s',
    )

    package_logger = logging.getLogger(package_name)
    package_logger.handlers.clear()

    # do not attache the same handler twice
    handler = logging.StreamHandler(sys.stdout)
    handler.setFormatter(formatter)

    counting_handler = CountingHandler(_module_record_counters)

    # Module scoped loggers add formatter handler and disable propagation.
    package_logger.addHandler(handler)
    package_logger.addHandler(counting_handler)
    package_logger.propagate = False  # Because we have own handler.
    package_logger.setLevel(level)

    # Inform about tracing level (because of number of metrics).
    package_logger.log(TRACE, 'Package logger trace messages enabled.')

    # Prepare main log to be used by main entry point module
    # (because you cannot create logger before initialization).
    log.debug(
        'setting level=%s for %r package', logging.getLevelName(log.getEffectiveLevel()),
        package_name
    ) 
开发者ID:intel,项目名称:workload-collocation-agent,代码行数:38,代码来源:logger.py

示例10: init_logging

# 需要导入模块: import logging [as 别名]
# 或者: from logging import addLevelName [as 别名]
def init_logging(cli_arguments):
    # This needs a separate 'Lector' in the os.path.join because
    # application name isn't explicitly set in this module

    os.makedirs(location_prefix, exist_ok=True)

    log_level = 30  # Warning and above
    # Set log level according to command line arguments
    try:
        if cli_arguments[1] == 'debug':
            log_level = 10  # Debug and above
            print('Debug logging enabled')
            try:
                os.remove(logger_filename)  # Remove old log for clarity
            except FileNotFoundError:
                pass
    except IndexError:
        pass

    # Create logging object
    logging.basicConfig(
        filename=logger_filename,
        filemode='a',
        format='%(asctime)s,%(msecs)d %(name)s %(levelname)s %(message)s',
        datefmt='%Y/%m/%d  %H:%M:%S',
        level=log_level)
    logging.addLevelName(60, 'HAMMERTIME')  ## Messages that MUST be logged

    return logging.getLogger('lector.main') 
开发者ID:BasioMeusPuga,项目名称:Lector,代码行数:31,代码来源:logger.py

示例11: __init__

# 需要导入模块: import logging [as 别名]
# 或者: from logging import addLevelName [as 别名]
def __init__(self, name, level=logging.NOTSET):
        super().__init__(name, level)
        # Use WitFormatter for info level
        _handler = logging.StreamHandler(sys.stdout)
        _handler.setFormatter(WitFormatter())
        logging.basicConfig(level=logging.INFO, handlers=[_handler])

        logging.addLevelName(VERBOSE, 'VERBOSE')
        logging.addLevelName(TRACE, 'TRACE')
        logging.addLevelName(SPAM, 'SPAM') 
开发者ID:sifive,项目名称:wit,代码行数:12,代码来源:witlogger.py

示例12: setUp

# 需要导入模块: import logging [as 别名]
# 或者: from logging import addLevelName [as 别名]
def setUp(self):
        BaseTest.setUp(self)
        for k, v in my_logging_levels.items():
            logging.addLevelName(k, v) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:6,代码来源:test_logging.py

示例13: get_logger

# 需要导入模块: import logging [as 别名]
# 或者: from logging import addLevelName [as 别名]
def get_logger():
    '''
    Returns logger used by multiprocessing
    '''
    global _logger
    import logging, atexit

    logging._acquireLock()
    try:
        if not _logger:

            _logger = logging.getLogger(LOGGER_NAME)
            _logger.propagate = 0
            logging.addLevelName(SUBDEBUG, 'SUBDEBUG')
            logging.addLevelName(SUBWARNING, 'SUBWARNING')

            # XXX multiprocessing should cleanup before logging
            if hasattr(atexit, 'unregister'):
                atexit.unregister(_exit_function)
                atexit.register(_exit_function)
            else:
                atexit._exithandlers.remove((_exit_function, (), {}))
                atexit._exithandlers.append((_exit_function, (), {}))

    finally:
        logging._releaseLock()

    return _logger 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:30,代码来源:util.py

示例14: setup

# 需要导入模块: import logging [as 别名]
# 或者: from logging import addLevelName [as 别名]
def setup(level = 0):
    """Sets up the global logging environment"""
    formatstr = "%(levelname)-8s: %(name)-20s: %(message)s"
    logging.basicConfig(format = formatstr)
    rootlogger = logging.getLogger('')
    rootlogger.setLevel(logging.DEBUG + 1 - level)
    for i in range(1, 9):
        logging.addLevelName(logging.DEBUG - i, "DEBUG" + str(i)) 
开发者ID:virtualrealitysystems,项目名称:aumfor,代码行数:10,代码来源:debug.py

示例15: _create_trace_loglevel

# 需要导入模块: import logging [as 别名]
# 或者: from logging import addLevelName [as 别名]
def _create_trace_loglevel(logging):
    "Add TRACE log level and Logger.trace() method."

    logging.TRACE = 5
    logging.addLevelName(logging.TRACE, "TRACE")

    def _trace(logger, message, *args, **kwargs):
        if logger.isEnabledFor(logging.TRACE):
            logger._log(logging.TRACE, message, args, **kwargs)

    logging.Logger.trace = _trace 
开发者ID:dwavesystems,项目名称:dwave-hybrid,代码行数:13,代码来源:__init__.py


注:本文中的logging.addLevelName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。