Esempio n. 1
0
    def test_logger(self):
        """The WF logger should not affect other loggers."""
        from workflow import engine

        logging.root.handlers = []
        engine.LOG.handlers = []

        other_logger = logging.getLogger('other')
        wf_logger = engine.get_logger('workflow.test')

        test_io = StringIO()
        root_io = StringIO()
        other_io = StringIO()

        logging.root.addHandler(logging.StreamHandler(root_io))
        other_logger.addHandler(logging.StreamHandler(other_io))
        wf_logger.addHandler(logging.StreamHandler(test_io))

        # set the root level to WARNING; wf should honour parent level
        logging.root.setLevel(logging.WARNING)

        logging.warn('root warn')
        other_logger.warn('other warn')
        wf_logger.warn('wf warn')

        logging.info('root info')
        other_logger.info('other info')
        wf_logger.info('wf info')

        self.assertEqual(root_io.getvalue(), "root warn\nother warn\n",
                         "Root logger should have two msgs")
        self.assertEqual(other_io.getvalue(), "other warn\n",
                         "Other logger should have one msg")
        self.assertEqual(test_io.getvalue(), "wf warn\n",
                         "Wf logger should have one msg")

        root_io.seek(0)
        other_io.seek(0)
        test_io.seek(0)

        # now set too to DEBUG and wf to INFO
        logging.root.setLevel(logging.DEBUG)
        engine.reset_all_loggers(logging.WARNING)

        logging.warn('root warn')
        other_logger.warn('other warn')
        wf_logger.warn('wf warn')

        logging.info('root info')
        other_logger.info('other info')
        wf_logger.info('wf info')

        self.assertEqual(root_io.getvalue(), "root warn\nother warn\n"
                         "root info\nother info\n",
                         "Root logger should have four msgs")
        self.assertEqual(other_io.getvalue(), "other warn\nother info\n",
                         "Other logger should have two msg")
        self.assertEqual(test_io.getvalue(), "wf warn\n",
                         "Wf logger should have one msg")
Esempio n. 2
0
    def test_logger(self):
        """The WF logger should not affect other loggers."""
        from workflow import engine

        logging.root.handlers = []
        engine.LOG.handlers = []

        other_logger = logging.getLogger('other')
        wf_logger = engine.get_logger('workflow.test')

        test_io = StringIO()
        root_io = StringIO()
        other_io = StringIO()

        logging.root.addHandler(logging.StreamHandler(root_io))
        other_logger.addHandler(logging.StreamHandler(other_io))
        wf_logger.addHandler(logging.StreamHandler(test_io))

        # set the root level to WARNING; wf should honour parent level
        logging.root.setLevel(logging.WARNING)

        logging.warn('root warn')
        other_logger.warn('other warn')
        wf_logger.warn('wf warn')

        logging.info('root info')
        other_logger.info('other info')
        wf_logger.info('wf info')

        self.assertEqual(root_io.getvalue(), "root warn\nother warn\n",
                         "Root logger should have two msgs")
        self.assertEqual(other_io.getvalue(), "other warn\n",
                         "Other logger should have one msg")
        self.assertEqual(test_io.getvalue(), "wf warn\n",
                         "Wf logger should have one msg")

        root_io.seek(0)
        other_io.seek(0)
        test_io.seek(0)

        # now set too to DEBUG and wf to INFO
        logging.root.setLevel(logging.DEBUG)
        engine.reset_all_loggers(logging.WARNING)

        logging.warn('root warn')
        other_logger.warn('other warn')
        wf_logger.warn('wf warn')

        logging.info('root info')
        other_logger.info('other info')
        wf_logger.info('wf info')

        self.assertEqual(root_io.getvalue(), "root warn\nother warn\n"
                         "root info\nother info\n",
                         "Root logger should have four msgs")
        self.assertEqual(other_io.getvalue(), "other warn\nother info\n",
                         "Other logger should have two msg")
        self.assertEqual(test_io.getvalue(), "wf warn\n",
                         "Wf logger should have one msg")
Esempio n. 3
0
        sys.exit(2)

    kw_args = {}
    output = None
    verbose = False
    for o, a in opts:
        if o in ("-v", '--verbose'):
            verbose = True
        elif o in ("-h", "--help"):
            usage()
            sys.exit()
        elif o in ("-e", "--level"):
            try:
                level = int(a)
                main_engine.set_global_level(level)
                main_engine.reset_all_loggers(level)
            except:
                print 'The argument to verbose must be integer'
                sys.exit(2)
        elif o in ('-v', '--verbose'):
            kw_args['verbose'] = True
        elif o in ('-p', '--places'):
            kw_args['places'] = a.split(',')
        elif o in ('-l', '--list'):
            kw_args['listwf'] = True
        else:
            assert False, "unhandled option %s" % o

    if (not len(args) or not len(opts)) and 'listwf' not in kw_args:
        usage()
        sys.exit()
Esempio n. 4
0
        sys.exit(2)

    kw_args = {}
    output = None
    verbose = False
    for o, a in opts:
        if o in ("-v", '--verbose'):
            verbose = True
        elif o in ("-h", "--help"):
            usage()
            sys.exit()
        elif o in ("-e", "--level"):
            try:
                level = int(a)
                main_engine.set_global_level(level)
                main_engine.reset_all_loggers(level)
            except:
                print 'The argument to verbose must be integer'
                sys.exit(2)
        elif o in ('-v', '--verbose'):
            kw_args['verbose'] = True
        elif o in ('-p', '--places'):
            kw_args['places'] = a.split(',')
        elif o in ('-l', '--list'):
            kw_args['listwf'] = True
        else:
            assert False, "unhandled option %s" % o

    if (not len(args) or not len(opts)) and 'listwf' not in kw_args:
        usage()
        sys.exit()