示例#1
0
 def __call__(self):
     with substate_context(self.context):
         self.ready_queue.put(True)
         log.debug("Running " + self.context)
         try:
             result = self.target()
         except Exception as err:
             log.fatal("Error in sub-process: %s", traceback.format_exc())
             raise err
     return result
示例#2
0
    def test_pre_init_logger(self):
        """Test that logging before initializing the logger works
        """
        log.fatal("Test")

        # Nothing should be logged yet
        self.assertEqual(len(self.log_stream.getvalue()), 0)

        log.initialize()

        # Something should be logged here
        self.assertNotEqual(len(self.log_stream.getvalue()), 0)
示例#3
0
    def test_pre_init_logger(self):
        """Test that logging before initializing the logger works
        """
        log.fatal("Test")

        # Nothing should be logged yet
        self.assertEqual(len(self.log_stream.getvalue()), 0)

        log.initialize()

        # Something should be logged here
        self.assertNotEqual(len(self.log_stream.getvalue()), 0)
示例#4
0
    def test_file_logger_writes_to_file(self):
        """Test logging to file writes something to the log file
        """
        with tempfile.NamedTemporaryFile() as temp:
            log.initialize(filename=temp.name, no_backups=0)
            log.fatal("Test")
            log.close()

            # Make sure file exists
            self.assertTrue(os.path.isfile(temp.name))

            lines = temp.readlines()
            # There should be exactly one line in the file now
            self.assertEqual(len(lines), 1)
示例#5
0
    def test_fatal_console_logging(self):
        """Test the most basic console logging at the fatal level
        """
        log.initialize(console_level=logging.INFO)
        log.fatal("Test")
        log.close()
        # Something should be logged
        self.assertNotEqual(len(self.log_stream.getvalue()), 0)

        log.initialize(console_level=logging.DEBUG)
        log.fatal("Test")
        log.close()
        # Something should be logged
        self.assertNotEqual(len(self.log_stream.getvalue()), 0)
示例#6
0
    def test_fatal_console_logging(self):
        """Test the most basic console logging at the fatal level
        """
        log.initialize(console_level=logging.INFO)
        log.fatal("Test")
        log.close()
        # Something should be logged
        self.assertNotEqual(len(self.log_stream.getvalue()), 0)

        log.initialize(console_level=logging.DEBUG)
        log.fatal("Test")
        log.close()
        # Something should be logged
        self.assertNotEqual(len(self.log_stream.getvalue()), 0)
示例#7
0
    def test_file_logger_writes_to_file(self):
        """Test logging to file writes something to the log file
        """
        with tempfile.NamedTemporaryFile() as temp:
            log.initialize(filename=temp.name, no_backups=0)
            log.fatal("Test: %f", 3.1415)
            log.close()

            # Make sure file exists
            self.assertTrue(os.path.isfile(temp.name))

            lines = temp.readlines()
            # There should be exactly one line in the file now
            self.assertEqual(len(lines), 1)

            # The content should match the logged message
            self.assertRegexpMatches(str(lines[0]), r'Test: 3.1415')
示例#8
0
 def hello():
     """Logs a message
     """
     log.fatal("Hello")
 def hello():
     """Logs a message
     """
     log.fatal("Hello")