本文整理汇总了Python中logging.raiseExceptions方法的典型用法代码示例。如果您正苦于以下问题:Python logging.raiseExceptions方法的具体用法?Python logging.raiseExceptions怎么用?Python logging.raiseExceptions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类logging
的用法示例。
在下文中一共展示了logging.raiseExceptions方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_error_handling
# 需要导入模块: import logging [as 别名]
# 或者: from logging import raiseExceptions [as 别名]
def test_error_handling(self):
h = TestStreamHandler(BadStream())
r = logging.makeLogRecord({})
old_raise = logging.raiseExceptions
try:
h.handle(r)
self.assertIs(h.error_record, r)
h = logging.StreamHandler(BadStream())
with support.captured_stderr() as stderr:
h.handle(r)
msg = '\nRuntimeError: deliberate mistake\n'
self.assertIn(msg, stderr.getvalue())
logging.raiseExceptions = False
with support.captured_stderr() as stderr:
h.handle(r)
self.assertEqual('', stderr.getvalue())
finally:
logging.raiseExceptions = old_raise
# -- The following section could be moved into a server_helper.py module
# -- if it proves to be of wider utility than just test_logging
示例2: test_error_handling
# 需要导入模块: import logging [as 别名]
# 或者: from logging import raiseExceptions [as 别名]
def test_error_handling(self):
h = TestStreamHandler(BadStream())
r = logging.makeLogRecord({})
old_raise = logging.raiseExceptions
old_stderr = sys.stderr
try:
h.handle(r)
self.assertIs(h.error_record, r)
h = logging.StreamHandler(BadStream())
sys.stderr = sio = io.StringIO()
h.handle(r)
self.assertIn('\nRuntimeError: deliberate mistake\n',
sio.getvalue())
logging.raiseExceptions = False
sys.stderr = sio = io.StringIO()
h.handle(r)
self.assertEqual('', sio.getvalue())
finally:
logging.raiseExceptions = old_raise
sys.stderr = old_stderr
# -- The following section could be moved into a server_helper.py module
# -- if it proves to be of wider utility than just test_logging
示例3: Parser_debug
# 需要导入模块: import logging [as 别名]
# 或者: from logging import raiseExceptions [as 别名]
def Parser_debug(enable, stream=None):
'''
Enables/Disables debug logger for parser.py
NOTE: This is not really multi-thread friendly
@param stream: StringIO stream to use
@param enable: Enable/disable debug stream
'''
global debug
debug = enable
if enable:
logging.raiseExceptions = False
log.setLevel(logging.DEBUG)
ch = logging.StreamHandler(stream)
log.addHandler(ch)
示例4: callHandlers
# 需要导入模块: import logging [as 别名]
# 或者: from logging import raiseExceptions [as 别名]
def callHandlers(self, record):
# this is the same as Python 3.5's logging.Logger.callHandlers
c = self
found = 0
while c:
for hdlr in c.handlers:
found = found + 1
if record.levelno >= hdlr.level:
hdlr.handle(record)
if not c.propagate:
c = None # break out
else:
c = c.parent
if (found == 0):
if logging.lastResort:
if record.levelno >= logging.lastResort.level:
logging.lastResort.handle(record)
elif logging.raiseExceptions and not self.manager.emittedNoHandlerWarning:
sys.stderr.write("No handlers could be found for logger"
" \"%s\"\n" % self.name)
self.manager.emittedNoHandlerWarning = True
示例5: test_unknown_exception
# 需要导入模块: import logging [as 别名]
# 或者: from logging import raiseExceptions [as 别名]
def test_unknown_exception(self, mock_session):
"""Test botocore general ClientError."""
logging.disable(logging.NOTSET)
mock_session.client = MagicMock()
unit_crawler = AWSOrgUnitCrawler(self.account)
unit_crawler._init_session()
unit_crawler._client.list_roots.side_effect = Exception("unknown error")
with self.assertLogs(logger=crawler_log, level=logging.raiseExceptions):
unit_crawler.crawl_account_hierarchy()
示例6: handleError
# 需要导入模块: import logging [as 别名]
# 或者: from logging import raiseExceptions [as 别名]
def handleError(self, record: logging.LogRecord) -> None:
if logging.raiseExceptions:
# Fail the test if the log message is bad (emit failed).
# The default behavior of logging is to print "Logging error"
# to stderr with the call stack and some extra details.
# pytest wants to make such mistakes visible during testing.
raise
示例7: test_last_resort
# 需要导入模块: import logging [as 别名]
# 或者: from logging import raiseExceptions [as 别名]
def test_last_resort(self):
# Test the last resort handler
root = self.root_logger
root.removeHandler(self.root_hdlr)
old_lastresort = logging.lastResort
old_raise_exceptions = logging.raiseExceptions
try:
with support.captured_stderr() as stderr:
root.debug('This should not appear')
self.assertEqual(stderr.getvalue(), '')
root.warning('Final chance!')
self.assertEqual(stderr.getvalue(), 'Final chance!\n')
# No handlers and no last resort, so 'No handlers' message
logging.lastResort = None
with support.captured_stderr() as stderr:
root.warning('Final chance!')
msg = 'No handlers could be found for logger "root"\n'
self.assertEqual(stderr.getvalue(), msg)
# 'No handlers' message only printed once
with support.captured_stderr() as stderr:
root.warning('Final chance!')
self.assertEqual(stderr.getvalue(), '')
# If raiseExceptions is False, no message is printed
root.manager.emittedNoHandlerWarning = False
logging.raiseExceptions = False
with support.captured_stderr() as stderr:
root.warning('Final chance!')
self.assertEqual(stderr.getvalue(), '')
finally:
root.addHandler(self.root_hdlr)
logging.lastResort = old_lastresort
logging.raiseExceptions = old_raise_exceptions
示例8: setUp
# 需要导入模块: import logging [as 别名]
# 或者: from logging import raiseExceptions [as 别名]
def setUp(self):
super(ShutdownTest, self).setUp()
self.called = []
raise_exceptions = logging.raiseExceptions
self.addCleanup(setattr, logging, 'raiseExceptions', raise_exceptions)
示例9: test_with_other_error_in_acquire_without_raise
# 需要导入模块: import logging [as 别名]
# 或者: from logging import raiseExceptions [as 别名]
def test_with_other_error_in_acquire_without_raise(self):
logging.raiseExceptions = False
self._test_with_failure_in_method('acquire', IndexError)
示例10: test_with_other_error_in_flush_without_raise
# 需要导入模块: import logging [as 别名]
# 或者: from logging import raiseExceptions [as 别名]
def test_with_other_error_in_flush_without_raise(self):
logging.raiseExceptions = False
self._test_with_failure_in_method('flush', IndexError)
示例11: test_with_other_error_in_acquire_with_raise
# 需要导入模块: import logging [as 别名]
# 或者: from logging import raiseExceptions [as 别名]
def test_with_other_error_in_acquire_with_raise(self):
logging.raiseExceptions = True
self.assertRaises(IndexError, self._test_with_failure_in_method,
'acquire', IndexError)
示例12: test_with_other_error_in_flush_with_raise
# 需要导入模块: import logging [as 别名]
# 或者: from logging import raiseExceptions [as 别名]
def test_with_other_error_in_flush_with_raise(self):
logging.raiseExceptions = True
self.assertRaises(IndexError, self._test_with_failure_in_method,
'flush', IndexError)
示例13: test_with_other_error_in_close_with_raise
# 需要导入模块: import logging [as 别名]
# 或者: from logging import raiseExceptions [as 别名]
def test_with_other_error_in_close_with_raise(self):
logging.raiseExceptions = True
self.assertRaises(IndexError, self._test_with_failure_in_method,
'close', IndexError)
示例14: test_log_invalid_level_with_raise
# 需要导入模块: import logging [as 别名]
# 或者: from logging import raiseExceptions [as 别名]
def test_log_invalid_level_with_raise(self):
with support.swap_attr(logging, 'raiseExceptions', True):
self.assertRaises(TypeError, self.logger.log, '10', 'test message')
示例15: test_log_invalid_level_no_raise
# 需要导入模块: import logging [as 别名]
# 或者: from logging import raiseExceptions [as 别名]
def test_log_invalid_level_no_raise(self):
with support.swap_attr(logging, 'raiseExceptions', False):
self.logger.log('10', 'test message') # no exception happens