本文整理汇总了Python中twisted.python.log.removeObserver函数的典型用法代码示例。如果您正苦于以下问题:Python removeObserver函数的具体用法?Python removeObserver怎么用?Python removeObserver使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了removeObserver函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
def main(self):
"""Parse arguments and run the script's main function via ``react``."""
observer = None
try:
if not self.log_directory.exists():
self.log_directory.makedirs()
log_path = self.log_directory.child(
b"%s-%d.log" % (os.path.basename(self.sys_module.argv[0]),
os.getpid()))
log_file = log_path.open("a")
observer = FileLogObserver(log_file).emit
addObserver(observer)
msg("Arguments: %s" % (self.sys_module.argv,))
except (OSError, IOError):
pass
options = self._parse_options(self.sys_module.argv[1:])
# XXX: We shouldn't be using this private _reactor API. See
# https://twistedmatrix.com/trac/ticket/6200 and
# https://twistedmatrix.com/trac/ticket/7527
self._react(self.script.main, (options,), _reactor=self._reactor)
# Not strictly necessary, but nice cleanup for tests:
if observer is not None:
removeObserver(observer)
log_file.close()
示例2: _test_level
def _test_level(self, level, messages_number):
observer = LevelFileLogObserver(self.log_file, level)
log.addObserver(observer)
self.LOG.debug('test debug')
self.LOG.info('test info')
self.LOG.warning('test warning')
self.LOG.error('test error')
self.LOG.critical('test critical')
log.removeObserver(observer)
with open(self.log_path) as f:
lines = [line.strip() for line in f.readlines()]
self.assertEqual(len(lines), messages_number)
for line in lines:
m = re.match(self.rx, line)
self.assertIsNotNone(m)
time, level_name, system, entry_text = m.groups()
time = datetime.strptime(time, "%Y-%m-%d %H:%M:%S")
entry_level = logging.getLevelName(level_name)
self.assertGreaterEqual(entry_level, level)
self.assertEqual(system, __name__)
text = "test {0}".format(level_name.lower())
self.assertEqual(entry_text, text)
示例3: _remove
def _remove(self):
self._added -= 1
if self._added == 0:
log.removeObserver(self.gotEvent)
log._flushErrors = self._oldFE
log._ignore = self._oldIE
log._clearIgnores = self._oldCI
示例4: test_default_item_completed
def test_default_item_completed(self):
item = dict(name='name')
assert self.pipe.item_completed([], item, self.info) is item
# Check that failures are logged by default
fail = Failure(Exception())
results = [(True, 1), (False, fail)]
events = []
txlog.addObserver(events.append)
new_item = self.pipe.item_completed(results, item, self.info)
txlog.removeObserver(events.append)
self.flushLoggedErrors()
assert new_item is item
assert len(events) == 1
assert events[0]['logLevel'] == log.ERROR
assert events[0]['failure'] is fail
# disable failure logging and check again
self.pipe.LOG_FAILED_RESULTS = False
events = []
txlog.addObserver(events.append)
new_item = self.pipe.item_completed(results, item, self.info)
txlog.removeObserver(events.append)
self.flushLoggedErrors()
assert new_item is item
assert len(events) == 0
示例5: test_send_catch_log
def test_send_catch_log(self):
test_signal = object()
handlers_called = set()
def log_received(event):
handlers_called.add(log_received)
assert "error_handler" in event['message'][0]
assert event['logLevel'] == log.ERROR
txlog.addObserver(log_received)
dispatcher.connect(self.error_handler, signal=test_signal)
dispatcher.connect(self.ok_handler, signal=test_signal)
result = yield defer.maybeDeferred(self._get_result, test_signal, arg='test',
handlers_called=handlers_called)
assert self.error_handler in handlers_called
assert self.ok_handler in handlers_called
assert log_received in handlers_called
self.assertEqual(result[0][0], self.error_handler)
self.assert_(isinstance(result[0][1], Failure))
self.assertEqual(result[1], (self.ok_handler, "OK"))
txlog.removeObserver(log_received)
self.flushLoggedErrors()
dispatcher.disconnect(self.error_handler, signal=test_signal)
dispatcher.disconnect(self.ok_handler, signal=test_signal)
示例6: _tearDownLogFile
def _tearDownLogFile(self):
if self._logFileObserver is not None:
log.removeObserver(self._logFileObserver.emit)
self._logFileObserver = None
if self._logFileObject is not None:
self._logFileObject.close()
self._logFileObject = None
示例7: _exit
def _exit(self, reactor):
self.triggered = True
log.removeObserver(self._failure_observer)
try:
reactor.stop()
except error.ReactorNotRunning:
pass
示例8: stop
def stop(self):
"""
Remove all log observers previously set up by L{AppLogger.start}.
"""
log.msg("Server Shut Down.")
if self._observer is not None:
log.removeObserver(self._observer)
self._observer = None
示例9: stop
def stop(self):
"""
Print twistd stop log message.
"""
log.msg("Server Shut Down.")
if self._observer is not None:
log.removeObserver(self._observer)
self._observer = None
示例10: tearDown
def tearDown(self):
"""
Ensure the log observer added by L{setUp} is removed.
"""
try:
log.removeObserver(self.receiver._emit)
except ValueError:
# The test removed it already.
pass
示例11: test_error_logged_if_deferred_not_supported
def test_error_logged_if_deferred_not_supported(self):
test_handler = lambda: defer.Deferred()
log_events = []
txlog.addObserver(log_events.append)
dispatcher.connect(test_handler, test_signal)
self.manager.send(test_signal)
self.failUnless(log_events)
self.failUnless('Cannot return deferreds from signal handler' in str(log_events))
txlog.removeObserver(log_events.append)
dispatcher.disconnect(test_handler, test_signal)
示例12: signal_handler
def signal_handler(self, signo, frame):
try:
log.msg('Rotating log %s' % self.log_filename)
log.removeObserver(self.log_observer.emit)
self.log_file.close()
self.setup_log(self.log_filename)
except:
msg = "Error in signal_handler:\n%s" % traceback.format_exc()
print msg
mail.error(msg)
示例13: test_write_to_logfile
def test_write_to_logfile(self):
with TemporaryDirectory() as tmpdir:
o = log.CarbonLogObserver()
o.log_to_dir(tmpdir)
addObserver(o)
log.creates('😀😀😀😀 test !!!!')
removeObserver(o)
with open(path.join(tmpdir, 'creates.log')) as logfile:
read_line = logfile.readline()
self.assertRegexpMatches(read_line, '.*😀😀😀😀 test !!!!')
示例14: test_error_logged_if_deferred_not_supported
def test_error_logged_if_deferred_not_supported(self):
test_signal = object()
test_handler = lambda: defer.Deferred()
log_events = []
txlog.addObserver(log_events.append)
dispatcher.connect(test_handler, test_signal)
send_catch_log(test_signal)
self.assertTrue(log_events)
self.assertIn("Cannot return deferreds from signal handler", str(log_events))
txlog.removeObserver(log_events.append)
self.flushLoggedErrors()
dispatcher.disconnect(test_handler, test_signal)
示例15: remove_log_observer
def remove_log_observer(self, observer=False):
"""
Remove a twisted.log observer
@type observer: method
@param observer: The name of the method specified in add_log_observer. If False, the last known log observer added will be removed
"""
if observer:
log.removeObserver(observer)
else:
log.removeObserver(self.log_observer)