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


Python LOG.removeHandler方法代码示例

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


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

示例1: test_value_error_raises_system_exit

# 需要导入模块: from cylc.flow import LOG [as 别名]
# 或者: from cylc.flow.LOG import removeHandler [as 别名]
    def test_value_error_raises_system_exit(self, mocked_glbl_cfg):
        """Test that a ValueError when writing to a log stream won't result
        in multiple exceptions (what could lead to infinite loop in some
        occasions. Instead, it **must** raise a SystemExit"""
        with tempfile.NamedTemporaryFile() as tf:
            # mock objects used when creating the file handler
            mocked = mock.MagicMock()
            mocked_glbl_cfg.return_value = mocked
            mocked.get_derived_host_item.return_value = tf.name
            mocked.get.return_value = 100
            file_handler = TimestampRotatingFileHandler("suiteA", False)
            # next line is important as pytest can have a "Bad file descriptor"
            # due to a FileHandler with default "a" (pytest tries to r/w).
            file_handler.mode = "a+"

            # enable the logger
            LOG.setLevel(logging.INFO)
            LOG.addHandler(file_handler)

            # Disable raising uncaught exceptions in logging, due to file
            # handler using stdin.fileno. See the following links for more.
            # https://github.com/pytest-dev/pytest/issues/2276 &
            # https://github.com/pytest-dev/pytest/issues/1585
            logging.raiseExceptions = False

            # first message will initialize the stream and the handler
            LOG.info("What could go")

            # here we change the stream of the handler
            old_stream = file_handler.stream
            file_handler.stream = mock.MagicMock()
            file_handler.stream.seek = mock.MagicMock()
            # in case where
            file_handler.stream.seek.side_effect = ValueError

            try:
                # next call will call the emit method and use the mocked stream
                LOG.info("wrong?!")
                self.fail("Exception SystemError was not raised")
            except SystemExit:
                pass
            finally:
                # clean up
                file_handler.stream = old_stream
                # for log_handler in LOG.handlers:
                #     log_handler.close()
                file_handler.close()
                LOG.removeHandler(file_handler)
                logging.raiseExceptions = True
开发者ID:cylc,项目名称:cylc,代码行数:51,代码来源:test_loggingutil.py

示例2: test_ioerror_is_ignored

# 需要导入模块: from cylc.flow import LOG [as 别名]
# 或者: from cylc.flow.LOG import removeHandler [as 别名]
    def test_ioerror_is_ignored(self, mocked_suite_srv_files_mgr,
                                mocked_suite_db_mgr, mocked_broadcast_mgr):
        """Test that IOError's are ignored when closing Scheduler logs.
        When a disk errors occurs, the scheduler.close_logs method may
        result in an IOError. This, combined with other variables, may cause
        an infinite loop. So it is better that it is ignored."""
        mocked_suite_srv_files_mgr.return_value\
            .get_suite_source_dir.return_value = "."
        options = Options()
        args = ["suiteA"]
        scheduler = Scheduler(is_restart=False, options=options, args=args)

        handler = mock.MagicMock()
        handler.close.side_effect = IOError
        handler.level = logging.INFO
        LOG.addHandler(handler)

        scheduler.close_logs()
        self.assertEqual(1, handler.close.call_count)
        LOG.removeHandler(handler)
开发者ID:cylc,项目名称:cylc,代码行数:22,代码来源:test_scheduler.py


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