def start(self, application): if self.observerFactory is not None: self.observer = self.observerFactory() if self.observer is not None: logger.publisher.addObserver(self.observer, False) legacyLog.defaultObserver.stop() legacyLog.defaultObserver = None legacyLog.addObserver(log.LegacyAdapter()) self._initialLog()
def test_legacy_has_both_format_and__format(self): """ An error is reported if an event has both 'format' and '_format' keys. """ legacy_observer = log.LegacyAdapter() legacylog.addObserver(legacy_observer) self.addCleanup(legacylog.removeObserver, legacy_observer) legacylog.msg("test", _format="%(test)s") self.assertEqual(len(self.observer), 2) self.assertEqual(self.observer[0], log.double_format_error)
def test_legacy_emitter(self): """Test the events logged with the legacy logger are not lost.""" observer = log.LegacyAdapter() legacylog.addObserver(observer) self.addCleanup(legacylog.removeObserver, observer) legacylog.msg("test") legacylog.err(RuntimeError("error")) err = self.flushLoggedErrors(RuntimeError) self.assertEqual(len(self.observer), 2) self.assertEqual(len(err), 1)
def test_legacy_rename_format_key(self): """ If the event has a 'format' key, rename it to '_format'. """ legacy_observer = log.LegacyAdapter() legacylog.addObserver(legacy_observer) self.addCleanup(legacylog.removeObserver, legacy_observer) legacylog.msg("test") self.assertEqual(len(self.observer), 1) event = self.observer[0] self.assertNotIn("format", event) self.assertIn("_format", event)