本文整理汇总了Python中logging._levelToName方法的典型用法代码示例。如果您正苦于以下问题:Python logging._levelToName方法的具体用法?Python logging._levelToName怎么用?Python logging._levelToName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类logging
的用法示例。
在下文中一共展示了logging._levelToName方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: make_logging_level_names_consistent
# 需要导入模块: import logging [as 别名]
# 或者: from logging import _levelToName [as 别名]
def make_logging_level_names_consistent():
"""Rename the standard library's logging levels to match Twisted's.
Twisted's new logging system in `twisted.logger` that is.
"""
for level in list(logging._levelToName):
if level == logging.NOTSET:
# When the logging level is not known in Twisted it's rendered as
# a hyphen. This is not a common occurrence with `logging` but we
# cater for it anyway.
name = "-"
elif level == logging.WARNING:
# "Warning" is more consistent with the other level names than
# "warn", so there is a fault in Twisted here. However it's easier
# to change the `logging` module to match Twisted than vice-versa.
name = "warn"
else:
# Twisted's level names are all lower-case.
name = logging.getLevelName(level).lower()
# For a preexisting level this will _replace_ the name.
logging.addLevelName(level, name)
示例2: assemble_global_handler
# 需要导入模块: import logging [as 别名]
# 或者: from logging import _levelToName [as 别名]
def assemble_global_handler(logger):
if LoggerFactory.LOG_DIR:
for level in LoggerFactory.levels:
if level >= LoggerFactory.LEVEL:
level_logger_name = logging._levelToName[level]
logger.addHandler(LoggerFactory.get_global_hanlder(level_logger_name, level))
if LoggerFactory.append_to_parent_log and LoggerFactory.PARENT_LOG_DIR:
for level in LoggerFactory.levels:
if level >= LoggerFactory.LEVEL:
level_logger_name = logging._levelToName[level]
logger.addHandler(LoggerFactory.get_global_hanlder(level_logger_name, level, LoggerFactory.PARENT_LOG_DIR))
示例3: get_log_levels
# 需要导入模块: import logging [as 别名]
# 或者: from logging import _levelToName [as 别名]
def get_log_levels():
"""
Return a list of available log level names
"""
try:
level_to_name = logging._levelToName
except AttributeError:
level_to_name = dict([(key, logging._levelNames[key])
for key in logging._levelNames
if isinstance(key, int)])
for level in sorted(level_to_name):
yield level_to_name[level]
示例4: pytest_configure
# 需要导入模块: import logging [as 别名]
# 或者: from logging import _levelToName [as 别名]
def pytest_configure(config):
"""Setup multiprocessing logging for loky testing"""
if sys.version_info >= (3, 4):
logging._levelToName[5] = "SUBDEBUG"
log = log_to_stderr(config.getoption("--loky-verbosity"))
log.handlers[0].setFormatter(logging.Formatter(
'[%(levelname)s:%(processName)s:%(threadName)s] %(message)s'))
warnings.simplefilter('always')
config.addinivalue_line("markers", "timeout")
config.addinivalue_line("markers", "broken_pool")
config.addinivalue_line("markers", "high_memory")
示例5: logger
# 需要导入模块: import logging [as 别名]
# 或者: from logging import _levelToName [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