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


Python PrintManager.error方法代码示例

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


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

示例1: test_error

# 需要导入模块: from DAS.utils.logger import PrintManager [as 别名]
# 或者: from DAS.utils.logger.PrintManager import error [as 别名]
 def test_error(self):
     "Test logger error method"
     old_stdout = sys.stdout
     logger = PrintManager(self.name) # verbose is irrelevant
     sys.stdout = StringIO()
     logger.error('test')
     result = sys.stdout.getvalue()
     expect = 'ERROR %s:%s test\n' % (self.name, funcname())
     self.assertEqual(expect, result)
     sys.stdout = old_stdout
开发者ID:ktf,项目名称:DAS,代码行数:12,代码来源:logger_t.py

示例2: Test

# 需要导入模块: from DAS.utils.logger import PrintManager [as 别名]
# 或者: from DAS.utils.logger.PrintManager import error [as 别名]
class Test(object):
    """
    This is a test task that prints a message (supplied in kwargs) to stdout.
    It will randomly sometimes raise exceptions (5%), spawn subtasks (4%) or
    disable resubmission of itself (1%).
    """
    task_title = "Test task"
    task_options = [{"name":"message", "type":"string",
                     "default":"hello world", "help":"Message to print"}]

    def __init__(self, **kwargs):
        self.logger = PrintManager('Test', kwargs.get('verbose', 0))
        self.name = kwargs['name']
        self.message = kwargs['message']
        self.index = kwargs['index']

    def __call__(self):
        self.logger.info('%s from index=%s' % (self.message, self.index))

        result = {}

        effect = random.random()
        if effect > 0.99:
            self.logger.info('..disabling resubmission')
            result['resubmit'] = False
        elif effect > 0.95:
            task = {'name':'spawn-of-%s' % self.index,
                    'classname':'Test',
                    'interval': random.randint(1,30),
                    'kwargs':{'message':'spawn-of-%s' % self.message}}
            effect2 = random.random()
            if effect2 > 0.50:
                task['only_once'] =  True
                self.logger.info('..spawning run-once task')
            elif effect2 > 0.25:
                task['max_runs'] = random.randint(1, 5)
                self.logger.info(\
                '..spawning task to run %s times' % task['max_runs'])
            else:
                task['only_before'] = time.time() + random.randint(1, 120)
                self.logger.info(\
                '..spawning task to run until %s' % task['only_before'])
            result['new_tasks'] = [task]
        elif effect > 0.90:
            self.logger.error('..raising an exception')
            raise

        return result
开发者ID:ktf,项目名称:DAS,代码行数:50,代码来源:Test.py


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