当前位置: 首页>>代码示例>>Python>>正文


Python DummyOptions.getLogger方法代码示例

本文整理汇总了Python中supervisor.tests.base.DummyOptions.getLogger方法的典型用法代码示例。如果您正苦于以下问题:Python DummyOptions.getLogger方法的具体用法?Python DummyOptions.getLogger怎么用?Python DummyOptions.getLogger使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在supervisor.tests.base.DummyOptions的用法示例。


在下文中一共展示了DummyOptions.getLogger方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_stdout_capturemode_single_buffer

# 需要导入模块: from supervisor.tests.base import DummyOptions [as 别名]
# 或者: from supervisor.tests.base.DummyOptions import getLogger [as 别名]
    def test_stdout_capturemode_single_buffer(self):
        # mike reported that comm events that took place within a single
        # output buffer were broken 8/20/2007
        from supervisor.events import ProcessCommunicationEvent
        from supervisor.events import subscribe

        events = []

        def doit(event):
            events.append(event)

        subscribe(ProcessCommunicationEvent, doit)
        BEGIN_TOKEN = ProcessCommunicationEvent.BEGIN_TOKEN
        END_TOKEN = ProcessCommunicationEvent.END_TOKEN
        data = BEGIN_TOKEN + "hello" + END_TOKEN
        options = DummyOptions()
        from supervisor.loggers import getLogger

        options.getLogger = getLogger  # actually use real logger
        logfile = "/tmp/log"
        config = DummyPConfig(
            options, "process1", "/bin/process1", stdout_logfile=logfile, stdout_capture_maxbytes=1000
        )
        process = DummyProcess(config)
        dispatcher = self._makeOne(process)

        try:
            dispatcher.output_buffer = data
            dispatcher.record_output()
            self.assertEqual(open(logfile, "r").read(), "")
            self.assertEqual(dispatcher.output_buffer, "")
            self.assertEqual(len(events), 1)

            event = events[0]
            from supervisor.events import ProcessCommunicationStdoutEvent

            self.assertEqual(event.__class__, ProcessCommunicationStdoutEvent)
            self.assertEqual(event.process, process)
            self.assertEqual(event.channel, "stdout")
            self.assertEqual(event.data, "hello")

        finally:
            try:
                dispatcher.capturelog.close()
                dispatcher.childlog.close()
                os.remove(logfile)
            except (OSError, IOError):
                pass
开发者ID:whenjonny,项目名称:tupppai-tools,代码行数:50,代码来源:test_dispatchers.py

示例2: test_stdout_capturemode_multiple_buffers

# 需要导入模块: from supervisor.tests.base import DummyOptions [as 别名]
# 或者: from supervisor.tests.base.DummyOptions import getLogger [as 别名]
    def test_stdout_capturemode_multiple_buffers(self):
        from supervisor.events import ProcessCommunicationEvent
        from supervisor.events import subscribe
        events = []
        def doit(event):
            events.append(event)
        subscribe(ProcessCommunicationEvent, doit)
        import string
        # ascii_letters for python 3
        letters = getattr(string, "letters", string.ascii_letters)
        digits = string.digits * 4
        BEGIN_TOKEN = ProcessCommunicationEvent.BEGIN_TOKEN
        END_TOKEN = ProcessCommunicationEvent.END_TOKEN
        data = (letters +  BEGIN_TOKEN + digits + END_TOKEN + letters)

        # boundaries that split tokens
        broken = data.split(':')
        first = broken[0] + ':'
        second = broken[1] + ':'
        third = broken[2]

        options = DummyOptions()
        from supervisor.loggers import getLogger
        options.getLogger = getLogger # actually use real logger
        logfile = '/tmp/log'
        config = DummyPConfig(options, 'process1', '/bin/process1',
                              stdout_logfile=logfile,
                              stdout_capture_maxbytes=10000)
        process = DummyProcess(config)
        dispatcher = self._makeOne(process)
        try:
            dispatcher.output_buffer = first
            dispatcher.record_output()
            [ x.flush() for x in dispatcher.childlog.handlers ]
            with open(logfile, 'r') as f:
                self.assertEqual(f.read(), letters)
            self.assertEqual(dispatcher.output_buffer, first[len(letters):])
            self.assertEqual(len(events), 0)

            dispatcher.output_buffer += second
            dispatcher.record_output()
            self.assertEqual(len(events), 0)
            [ x.flush() for x in dispatcher.childlog.handlers ]
            with open(logfile, 'r') as f:
                self.assertEqual(f.read(), letters)
            self.assertEqual(dispatcher.output_buffer, first[len(letters):])
            self.assertEqual(len(events), 0)

            dispatcher.output_buffer += third
            dispatcher.record_output()
            [ x.flush() for x in dispatcher.childlog.handlers ]
            with open(logfile, 'r') as f:
                self.assertEqual(f.read(), letters * 2)
            self.assertEqual(len(events), 1)
            event = events[0]
            from supervisor.events import ProcessCommunicationStdoutEvent
            self.assertEqual(event.__class__, ProcessCommunicationStdoutEvent)
            self.assertEqual(event.process, process)
            self.assertEqual(event.channel, 'stdout')
            self.assertEqual(event.data, digits)

        finally:
            try:
                dispatcher.capturelog.close()
                dispatcher.childlog.close()
                os.remove(logfile)
            except (OSError, IOError):
                pass
开发者ID:1T,项目名称:supervisor,代码行数:70,代码来源:test_dispatchers.py

示例3: test_stdout_capturemode_multiple_buffers

# 需要导入模块: from supervisor.tests.base import DummyOptions [as 别名]
# 或者: from supervisor.tests.base.DummyOptions import getLogger [as 别名]
    def test_stdout_capturemode_multiple_buffers(self):
        from supervisor.events import ProcessCommunicationEvent
        from supervisor.events import subscribe

        events = []

        def doit(event):
            events.append(event)

        subscribe(ProcessCommunicationEvent, doit)
        import string

        letters = string.letters
        digits = string.digits * 4
        BEGIN_TOKEN = ProcessCommunicationEvent.BEGIN_TOKEN
        END_TOKEN = ProcessCommunicationEvent.END_TOKEN
        data = letters + BEGIN_TOKEN + digits + END_TOKEN + letters

        # boundaries that split tokens
        broken = data.split(":")
        first = broken[0] + ":"
        second = broken[1] + ":"
        third = broken[2]

        options = DummyOptions()
        from supervisor.loggers import getLogger

        options.getLogger = getLogger  # actually use real logger
        logfile = "/tmp/log"
        config = DummyPConfig(
            options, "process1", "/bin/process1", stdout_logfile=logfile, stdout_capture_maxbytes=10000
        )
        process = DummyProcess(config)
        dispatcher = self._makeOne(process)
        try:
            dispatcher.output_buffer = first
            dispatcher.record_output()
            [x.flush() for x in dispatcher.childlog.handlers]
            self.assertEqual(open(logfile, "r").read(), letters)
            self.assertEqual(dispatcher.output_buffer, first[len(letters) :])
            self.assertEqual(len(events), 0)

            dispatcher.output_buffer += second
            dispatcher.record_output()
            self.assertEqual(len(events), 0)
            [x.flush() for x in dispatcher.childlog.handlers]
            self.assertEqual(open(logfile, "r").read(), letters)
            self.assertEqual(dispatcher.output_buffer, first[len(letters) :])
            self.assertEqual(len(events), 0)

            dispatcher.output_buffer += third
            dispatcher.record_output()
            [x.flush() for x in dispatcher.childlog.handlers]
            self.assertEqual(open(logfile, "r").read(), letters * 2)
            self.assertEqual(len(events), 1)
            event = events[0]
            from supervisor.events import ProcessCommunicationStdoutEvent

            self.assertEqual(event.__class__, ProcessCommunicationStdoutEvent)
            self.assertEqual(event.process, process)
            self.assertEqual(event.channel, "stdout")
            self.assertEqual(event.data, digits)

        finally:
            try:
                os.remove(logfile)
            except (OSError, IOError):
                pass
开发者ID:Jude7,项目名称:minos,代码行数:70,代码来源:test_dispatchers.py


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