• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python log.removeObserver函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中twisted.python.log.removeObserver函数的典型用法代码示例。如果您正苦于以下问题:Python removeObserver函数的具体用法?Python removeObserver怎么用?Python removeObserver使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了removeObserver函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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()
开发者ID:alex-docker,项目名称:flocker,代码行数:26,代码来源:script.py


示例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)
开发者ID:oblalex,项目名称:tx-logging,代码行数:31,代码来源:test_observers.py


示例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
开发者ID:andrewbird,项目名称:vodafone-mobile-connect,代码行数:7,代码来源:unittest.py


示例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
开发者ID:1012,项目名称:scrapy,代码行数:28,代码来源:test_pipeline_media.py


示例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)
开发者ID:jtwaleson,项目名称:scrapy,代码行数:26,代码来源:test_utils_signal.py


示例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
开发者ID:shelmesky,项目名称:twisted,代码行数:7,代码来源:runner.py


示例7: _exit

    def _exit(self, reactor):
        self.triggered = True
        log.removeObserver(self._failure_observer)

        try:
            reactor.stop()
        except error.ReactorNotRunning:
            pass
开发者ID:spreadflow,项目名称:spreadflow-core,代码行数:8,代码来源:spreadflow_twistd.py


示例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
开发者ID:RedMoons,项目名称:Study_Python_Beautifulsoup4,代码行数:8,代码来源:app.py


示例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
开发者ID:antong,项目名称:twisted,代码行数:8,代码来源:app.py


示例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
开发者ID:rcarmo,项目名称:divmod.org,代码行数:9,代码来源:test_stats.py


示例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)
开发者ID:Mimino666,项目名称:crawlmi,代码行数:10,代码来源:test_signal_manager.py


示例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)     
开发者ID:tadeck,项目名称:twicecache,代码行数:10,代码来源:twice.py


示例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 !!!!')
开发者ID:NixM0nk3y,项目名称:carbon,代码行数:11,代码来源:test_log.py


示例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)
开发者ID:jtwaleson,项目名称:scrapy,代码行数:12,代码来源:test_utils_signal.py


示例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)
开发者ID:sanmarcos,项目名称:Itaka,代码行数:12,代码来源:server.py


示例16: stopService

    def stopService(self):
        log.msg("Stopping %s" % self)
        service.MultiService.stopService(self)

        if self.periodic_task:
            self.periodic_task.stop()
            self.periodic_task = None

        if self.log_task:
            self.log_task.stop()
            self.log_task = None

        log.removeObserver(self.emit)
开发者ID:Acidburn0zzz,项目名称:build,代码行数:13,代码来源:metrics.py


示例17: disable

    def disable(self):
        if not self.enabled:
            return

        if self.periodic_task:
            self.periodic_task.stop()
            self.periodic_task = None

        if self.log_task:
            self.log_task.stop()
            self.log_task = None

        log.removeObserver(self.emit)
        self.enabled = False
开发者ID:kenygia,项目名称:buildbot,代码行数:14,代码来源:metrics.py


示例18: test_connectionLost

    def test_connectionLost(self):
        self.connectionLost = False
        def observer(event):
            self.assertTrue(event["isError"])
            self.assertTrue(event["message"])
            self.connectionLost = True

        try:
            log.addObserver(observer)
            self.message.connectionLost()
            self.assertTrue(self.connectionLost)
            self.assertIdentical(self.message.lines, None)
        finally:
            log.removeObserver(observer)
开发者ID:lvh,项目名称:firehub,代码行数:14,代码来源:test_incoming.py


示例19: emit

    def emit(self, level, message, **kwargs):
        def observer(eventDict):
            self.eventDict = eventDict

        twistedLogging.addObserver(observer)

        super(TestLogger, self).emit(level, message, **kwargs)

        twistedLogging.removeObserver(observer)

        self.emitted = {
            "level"  : level,
            "message": message,
            "kwargs" : kwargs,
        }
开发者ID:azbarcea,项目名称:calendarserver,代码行数:15,代码来源:test_log.py


示例20: close

    def close(self, flush_writer=True):

        def set_disconnected():
            self._writer = None
            self._set_state(State.disconnected)

        try:
            twisted_log.removeObserver(self.on_twisted_log)
        except ValueError:
            # it should be safe to call close() multiple times,
            # in this case we are not registered as the observer anymore
            pass

        d = self._close_writer(flush_writer)
        d.addCallback(defer.drop_param, set_disconnected)
        return d
开发者ID:pepribas,项目名称:F3AT,代码行数:16,代码来源:journaler.py



注:本文中的twisted.python.log.removeObserver函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python log.startLogging函数代码示例发布时间:2022-05-27
下一篇:
Python log.msg函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap