本文整理汇总了Python中logging._handlerList方法的典型用法代码示例。如果您正苦于以下问题:Python logging._handlerList方法的具体用法?Python logging._handlerList怎么用?Python logging._handlerList使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类logging
的用法示例。
在下文中一共展示了logging._handlerList方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: SetLogPrefix
# 需要导入模块: import logging [as 别名]
# 或者: from logging import _handlerList [as 别名]
def SetLogPrefix(prefix):
"""Adds a prefix to the log handler to identify the process.
Args:
prefix: The prefix string to append at the beginning of each line.
"""
formatter = logging.Formatter(
str(prefix) + ' [%(filename)s:%(lineno)d] %(levelname)s %(message)s')
logging._acquireLock()
try:
for handler in logging._handlerList:
if isinstance(handler, weakref.ref):
handler = handler()
if handler:
handler.setFormatter(formatter)
finally:
logging._releaseLock()
示例2: _setup_logging
# 需要导入模块: import logging [as 别名]
# 或者: from logging import _handlerList [as 别名]
def _setup_logging(self, config):
log_config_file = config[u'log'][u'config_file']
self._logger.info(u'Logging configuration file: ' + log_config_file)
try:
logging.config.fileConfig(log_config_file)
except Exception:
exc_type, exc_value, exc_traceback = sys.exc_info()
traceback.print_exception(exc_type, exc_value, exc_traceback, limit=2, file=sys.stderr)
raise PanoptesConfigurationError(
u'Could not instantiate logger with logging configuration provided in file "%s": (%s) %s' % (
log_config_file, exc_type, exc_value))
# Create a filter to rate limit logs so that a misconfiguration or failure does not make the disk I/O go
# beserk or fill up the disk space. We do this in code instead if configuration for two reasons:
# - It enforces a filter on every handler, so no chance of messing them up in configuration
# - We use fileConfig (nof dictConfig) to setup our logging and fileConfig does not support filter configuration
throttle = RateLimitingFilter(rate=config[u'log'][u'rate'], per=config[u'log'][u'per'],
burst=config[u'log'][u'burst'])
# Apply the filter to all handlers. Note that this would be a shared filter across ALL logs generated by this
# process and thus the rate/burst should be set appropriately high
for handler in logging._handlerList:
# _handlerList is a list of weakrefs, so the object returned has to be dereferenced
handler().addFilter(throttle)
示例3: tearDown
# 需要导入模块: import logging [as 别名]
# 或者: from logging import _handlerList [as 别名]
def tearDown(self):
"""Remove our logging stream, and restore the original logging
level."""
self.stream.close()
self.root_logger.removeHandler(self.root_hdlr)
while self.root_logger.handlers:
h = self.root_logger.handlers[0]
self.root_logger.removeHandler(h)
h.close()
self.root_logger.setLevel(self.original_logging_level)
logging._acquireLock()
try:
logging._levelNames.clear()
logging._levelNames.update(self.saved_level_names)
logging._handlers.clear()
logging._handlers.update(self.saved_handlers)
logging._handlerList[:] = self.saved_handler_list
loggerDict = logging.getLogger().manager.loggerDict
loggerDict.clear()
loggerDict.update(self.saved_loggers)
finally:
logging._releaseLock()
示例4: setUp
# 需要导入模块: import logging [as 别名]
# 或者: from logging import _handlerList [as 别名]
def setUp(self):
super(LoggerAdapterTest, self).setUp()
old_handler_list = logging._handlerList[:]
self.recording = RecordingHandler()
self.logger = logging.root
self.logger.addHandler(self.recording)
self.addCleanup(self.logger.removeHandler, self.recording)
self.addCleanup(self.recording.close)
def cleanup():
logging._handlerList[:] = old_handler_list
self.addCleanup(cleanup)
self.addCleanup(logging.shutdown)
self.adapter = logging.LoggerAdapter(logger=self.logger, extra=None)
示例5: resetLogging
# 需要导入模块: import logging [as 别名]
# 或者: from logging import _handlerList [as 别名]
def resetLogging():
""" Reset the handlers and loggers so that we
can rerun the tests starting from a blank slate.
"""
__pragma__("skip")
logging._handlerList = []
import weakref
logging._handlers = weakref.WeakValueDictionary()
logging.root = logging.RootLogger(logging.WARNING)
logging.Logger.root = logging.root
logging.Logger.manager = logging.Manager(logging.root)
logging.root.manager = logging.Logger.manager
__pragma__("noskip")
if __envir__.executor_name == __envir__.transpiler_name:
logging._resetLogging()
示例6: _fix_logging_lock_after_fork
# 需要导入模块: import logging [as 别名]
# 或者: from logging import _handlerList [as 别名]
def _fix_logging_lock_after_fork():
"""
HACK:
This is running in a child process, parent might hold some lock
while fork was called (but will be released only in a parent
process). This specifically applies to a logging module and
results in a deadlock (if one is unlucky). "Fix" this by
reinitialize a lock on all registered logging handlers
just after a fork() call, until fixed upstream:
https://bugs.python.org/issue6721
"""
if not hasattr(logging, '_handlerList'):
return
# pylint: disable=protected-access
for handler_ref in logging._handlerList:
handler = handler_ref()
if handler is None:
continue
if handler.lock:
handler.lock = type(handler.lock)()
示例7: fileConfig
# 需要导入模块: import logging [as 别名]
# 或者: from logging import _handlerList [as 别名]
def fileConfig(fname, defaults=None, disable_existing_loggers=True):
"""
Read the logging configuration from a ConfigParser-format file.
This can be called several times from an application, allowing an end user
the ability to select from various pre-canned configurations (if the
developer provides a mechanism to present the choices and load the chosen
configuration).
"""
import configparser
cp = configparser.ConfigParser(defaults)
if hasattr(fname, 'readline'):
cp.read_file(fname)
else:
cp.read(fname)
formatters = _create_formatters(cp)
# critical section
logging._acquireLock()
try:
logging._handlers.clear()
del logging._handlerList[:]
# Handlers add themselves to logging._handlers
handlers = _install_handlers(cp, formatters)
_install_loggers(cp, handlers, disable_existing_loggers)
finally:
logging._releaseLock()
示例8: get_logging__handlerList
# 需要导入模块: import logging [as 别名]
# 或者: from logging import _handlerList [as 别名]
def get_logging__handlerList(self):
# _handlerList is a list of weakrefs to handlers
return id(logging._handlerList), logging._handlerList, logging._handlerList[:]
示例9: fileConfig
# 需要导入模块: import logging [as 别名]
# 或者: from logging import _handlerList [as 别名]
def fileConfig(fname, defaults=None, disable_existing_loggers=True):
"""
Read the logging configuration from a ConfigParser-format file.
This can be called several times from an application, allowing an end user
the ability to select from various pre-canned configurations (if the
developer provides a mechanism to present the choices and load the chosen
configuration).
"""
import ConfigParser
cp = ConfigParser.ConfigParser(defaults)
if hasattr(fname, 'readline'):
cp.readfp(fname)
else:
cp.read(fname)
formatters = _create_formatters(cp)
# critical section
logging._acquireLock()
try:
logging._handlers.clear()
del logging._handlerList[:]
# Handlers add themselves to logging._handlers
handlers = _install_handlers(cp, formatters)
_install_loggers(cp, handlers, disable_existing_loggers)
finally:
logging._releaseLock()
示例10: setUp
# 需要导入模块: import logging [as 别名]
# 或者: from logging import _handlerList [as 别名]
def setUp(self):
"""Setup the default logging stream to an internal StringIO instance,
so that we can examine log output as we want."""
logger_dict = logging.getLogger().manager.loggerDict
logging._acquireLock()
try:
self.saved_handlers = logging._handlers.copy()
self.saved_handler_list = logging._handlerList[:]
self.saved_loggers = logger_dict.copy()
self.saved_level_names = logging._levelNames.copy()
finally:
logging._releaseLock()
# Set two unused loggers: one non-ASCII and one Unicode.
# This is to test correct operation when sorting existing
# loggers in the configuration code. See issue 8201.
logging.getLogger("\xab\xd7\xbb")
logging.getLogger(u"\u013f\u00d6\u0047")
self.root_logger = logging.getLogger("")
self.original_logging_level = self.root_logger.getEffectiveLevel()
self.stream = cStringIO.StringIO()
self.root_logger.setLevel(logging.DEBUG)
self.root_hdlr = logging.StreamHandler(self.stream)
self.root_formatter = logging.Formatter(self.log_format)
self.root_hdlr.setFormatter(self.root_formatter)
self.root_logger.addHandler(self.root_hdlr)
示例11: patch
# 需要导入模块: import logging [as 别名]
# 或者: from logging import _handlerList [as 别名]
def patch():
import logging
from . import format_exception
logging_format_exception = lambda exc_info: u''.join(format_exception(*exc_info))
if hasattr(logging, '_defaultFormatter'):
logging._defaultFormatter.format_exception = logging_format_exception
patchables = [handler() for handler in logging._handlerList if isinstance(handler(), StreamHandler)]
patchables = [handler for handler in patchables if handler.stream == sys.stderr]
patchables = [handler for handler in patchables if handler.formatter is not None]
for handler in patchables:
handler.formatter.formatException = logging_format_exception
示例12: patch_logging
# 需要导入模块: import logging [as 别名]
# 或者: from logging import _handlerList [as 别名]
def patch_logging(**kwargs):
"""
Replace `formatException` on every log handler / formatter we can find
**kwargs are those of stackprinter.format
"""
# this is based on https://github.com/Qix-/better-exceptions/blob/master/better_exceptions/log.py
def format_exc(exc_info):
msg = stackprinter.format(exc_info, **kwargs)
msg_indented = ' ' + '\n '.join(msg.split('\n')).strip()
return msg_indented
if hasattr(logging, '_defaultFormatter'):
logging._defaultFormatter.formatException = format_exc
handlers = [handler_ref() for handler_ref in logging._handlerList]
is_patchable = lambda handler: handler.formatter is not None
patchable_handlers = filter(is_patchable, handlers)
for hd in patchable_handlers:
hd.formatter.formatException = format_exc
# option A: use the root loger:
示例13: fileConfig
# 需要导入模块: import logging [as 别名]
# 或者: from logging import _handlerList [as 别名]
def fileConfig(fname, defaults=None, disable_existing_loggers=True):
"""
Read the logging configuration from a ConfigParser-format file.
This can be called several times from an application, allowing an end user
the ability to select from various pre-canned configurations (if the
developer provides a mechanism to present the choices and load the chosen
configuration).
"""
import configparser
if isinstance(fname, configparser.RawConfigParser):
cp = fname
else:
cp = configparser.ConfigParser(defaults)
if hasattr(fname, 'readline'):
cp.read_file(fname)
else:
cp.read(fname)
formatters = _create_formatters(cp)
# critical section
logging._acquireLock()
try:
logging._handlers.clear()
del logging._handlerList[:]
# Handlers add themselves to logging._handlers
handlers = _install_handlers(cp, formatters)
_install_loggers(cp, handlers, disable_existing_loggers)
finally:
logging._releaseLock()
示例14: tearDown
# 需要导入模块: import logging [as 别名]
# 或者: from logging import _handlerList [as 别名]
def tearDown(self):
"""Remove our logging stream, and restore the original logging
level."""
self.stream.close()
self.root_logger.removeHandler(self.root_hdlr)
while self.root_logger.handlers:
h = self.root_logger.handlers[0]
self.root_logger.removeHandler(h)
h.close()
self.root_logger.setLevel(self.original_logging_level)
logging._acquireLock()
try:
logging._levelToName.clear()
logging._levelToName.update(self.saved_level_to_name)
logging._nameToLevel.clear()
logging._nameToLevel.update(self.saved_name_to_level)
logging._handlers.clear()
logging._handlers.update(self.saved_handlers)
logging._handlerList[:] = self.saved_handler_list
loggerDict = logging.getLogger().manager.loggerDict
loggerDict.clear()
loggerDict.update(self.saved_loggers)
logger_states = self.logger_states
for name in self.logger_states:
if logger_states[name] is not None:
self.saved_loggers[name].disabled = logger_states[name]
finally:
logging._releaseLock()