本文整理匯總了Python中citest.base.JournalLogger.addHandler方法的典型用法代碼示例。如果您正苦於以下問題:Python JournalLogger.addHandler方法的具體用法?Python JournalLogger.addHandler怎麽用?Python JournalLogger.addHandler使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類citest.base.JournalLogger
的用法示例。
在下文中一共展示了JournalLogger.addHandler方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_context_logging
# 需要導入模塊: from citest.base import JournalLogger [as 別名]
# 或者: from citest.base.JournalLogger import addHandler [as 別名]
def test_context_logging(self):
offset = len(_journal_file.getvalue())
logger = JournalLogger('test_journal_logger')
logger.addHandler(JournalLogHandler(path=None))
citest_extra = {'foo':'bar'}
start_time = _journal_clock.last_time
JournalLogger.execute_in_context(
'The Test Context',
lambda: {logger.debug('Test Log Message')},
**citest_extra)
expect_sequence = [
{
'_title': 'The Test Context',
'_type': 'JournalContextControl',
'_timestamp': start_time + 1,
'_thread': current_thread().ident,
'control': 'BEGIN',
'foo': 'bar',
},
{
'_value': 'Test Log Message',
'_type': 'JournalMessage',
'_level': logging.DEBUG,
'_timestamp': start_time + 2,
'_thread': current_thread().ident,
'format': 'pre'
},
{
'_type': 'JournalContextControl',
'_timestamp': start_time + 3,
'_thread': current_thread().ident,
'control': 'END'
}
]
entry_str = _journal_file.getvalue()[offset:]
input_stream = RecordInputStream(BytesIO(entry_str))
for expect in expect_sequence:
json_str = next(input_stream)
json_dict = json_module.JSONDecoder().decode(json_str)
self.assertEqual(expect, json_dict)
示例2: test_journal_logger_with_custom_message
# 需要導入模塊: from citest.base import JournalLogger [as 別名]
# 或者: from citest.base.JournalLogger import addHandler [as 別名]
def test_journal_logger_with_custom_message(self):
offset = len(_journal_file.getvalue())
logger = JournalLogger(__name__)
logger.addHandler(JournalLogHandler(path=None))
citest_extra = {'foo':'bar', '_journal_message':'HELLO, JOURNAL'}
logger.debug('Hello, World!', extra={'citest_journal': citest_extra})
expect = {
'_value': 'HELLO, JOURNAL',
'_type': 'JournalMessage',
'_level': logging.DEBUG,
'_timestamp': _journal_clock.last_time,
'_thread': current_thread().ident,
'foo': 'bar',
'format': 'pre'
}
entry_str = _journal_file.getvalue()[offset:]
json_str = next(RecordInputStream(BytesIO(entry_str)))
json_dict = json_module.JSONDecoder().decode(json_str)
self.assertEqual(expect, json_dict)
示例3: test_journal_logger
# 需要導入模塊: from citest.base import JournalLogger [as 別名]
# 或者: from citest.base.JournalLogger import addHandler [as 別名]
def test_journal_logger(self):
offset = len(_journal_file.getvalue())
logger = JournalLogger('test_journal_logger')
logger.addHandler(JournalLogHandler(path=None))
citest_extra = {'foo':'bar', 'format':'FMT'}
logger.info('Hello, World!', extra={'citest_journal': citest_extra})
expect = {
'_value': 'Hello, World!',
'_type': 'JournalMessage',
'_level': logging.INFO,
'_timestamp': _journal_clock.last_time,
'_thread': current_thread().ident,
'foo': 'bar',
'format': 'FMT',
}
entry_str = _journal_file.getvalue()[offset:]
json_str = next(RecordInputStream(BytesIO(entry_str)))
json_dict = json_module.JSONDecoder().decode(json_str)
self.assertEqual(expect, json_dict)