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


Python logging.__dict__方法代码示例

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


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

示例1: _add_logger_level

# 需要导入模块: import logging [as 别名]
# 或者: from logging import __dict__ [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

示例2: add_filehandler

# 需要导入模块: import logging [as 别名]
# 或者: from logging import __dict__ [as 别名]
def add_filehandler(logger,style="default",flevel='DEBUG',
                   filename=None,filemode='w'):
    name = ""
    #-- define formats
    if style=='default':
        format  = '%(asctime)s %(name)-12s %(levelname)-7s %(message)s'
        datefmt = '%a, %d %b %Y %H:%M'
    elif style=='grandpa':
        format  = '# %(levelname)-7s %(message)s'
        datefmt = '%a, %d %b %Y %H:%M'
    elif style=='minimal':
        format = ''
        datefmt = '%a, %d %b %Y %H:%M'
    flevel = logging.__dict__[flevel.upper()]
    logging.basicConfig(level=flevel,
                        format=format,datefmt=datefmt,
                        filename=filename,filemode=filemode)
    fh = logging.FileHandler(filename)
    fh.setLevel(flevel)
    formatter = logging.Formatter(fmt=format,datefmt=datefmt)
    fh.setFormatter(formatter)
    logging.getLogger(name).addHandler(fh)
    logging.getLogger(name).handlers[-1].level = flevel
    return logging.getLogger(name) 
开发者ID:phoebe-project,项目名称:phoebe2,代码行数:26,代码来源:__init__.py

示例3: logger

# 需要导入模块: import logging [as 别名]
# 或者: from logging import __dict__ [as 别名]
def logger():
    getpid_patch = patch('logging.os.getpid', return_value=111)
    getpid_patch.start()
    time_patch = patch('logging.time.time', return_value=946725071.111111)
    time_patch.start()
    localzone_patch = patch('rfc5424logging.handler.get_localzone', return_value=timezone)
    localzone_patch.start()
    hostname_patch = patch('rfc5424logging.handler.socket.gethostname', return_value="testhostname")
    hostname_patch.start()
    connect_patch = patch('logging.handlers.socket.socket.connect', side_effect=connect_mock)
    connect_patch.start()
    sendall_patch = patch('logging.handlers.socket.socket.sendall', side_effect=connect_mock)
    sendall_patch.start()

    if '_levelNames' in logging.__dict__:
        # Python 2.7
        level_patch = patch.dict(logging._levelNames)
        level_patch.start()
    else:
        # Python 3.x
        level_patch1 = patch.dict(logging._levelToName)
        level_patch1.start()
        level_patch2 = patch.dict(logging._nameToLevel)
        level_patch2.start()

    logging.raiseExceptions = True
    logger = logging.getLogger()
    logger.setLevel(logging.DEBUG)
    yield logger

    getpid_patch.stop()
    time_patch.stop()
    localzone_patch.stop()
    hostname_patch.stop()
    connect_patch.stop()
    sendall_patch.stop()

    if '_levelNames' in logging.__dict__:
        # Python 2.7
        level_patch.stop()
    else:
        # Python 3.x
        level_patch1.stop()
        level_patch2.stop()

    Rfc5424SysLogAdapter._extra_levels_enabled = False 
开发者ID:jobec,项目名称:rfc5424-logging-handler,代码行数:48,代码来源:conftest.py


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