Exemplo n.º 1
0
    def test_removeHandler_success(self):
        """
        It removes and closes the handler, sending a notification.

        Handler is not called on further log events.
        """
        log_handler = InMemoryHandler()
        log_entry_id = manufacture.getUniqueInteger()
        log_entry = manufacture.getUniqueString()
        self.logger.addHandler(log_handler)
        callback = self.Mock()
        self.logger.subscribe('remove-handler', callback)
        self.assertIsNotEmpty(self.logger.getHandlers())

        self.logger.removeHandler(log_handler)

        # No entry is recorded by the handler.
        self.logger.log(log_entry_id, log_entry)
        self.assertIsEmpty(log_handler.history)

        # No handlers are there.
        self.assertIsEmpty(self.logger.getHandlers())

        self.assertEqual(1, callback.call_count)
        signal = callback.call_args[0][0]
        self.assertEqual(log_handler.name, signal.name)
Exemplo n.º 2
0
    def test_addFile_normal(self):
        """
        System test for adding a normal non-rotate file handler.
        """
        file_path, self.test_segments = manufacture.fs.makePathInTemp()
        self.config.file = file_path
        self.logger._configuration = self.config
        log_id = manufacture.getUniqueInteger()
        log_message = manufacture.getUniqueString()

        result = self.logger._addFile()

        self.assertIsInstance(FileHandler, result)
        self.assertEqual('File %s' % (self.config.file), result.name)

        # Add two log entries and close the logger.
        self.logger.log(log_id, log_message)
        self.logger.log(log_id + 1, log_message)
        self.logger.removeAllHandlers()

        # Check that file exists and it has the right content.
        self.assertTrue(manufacture.fs.exists(self.test_segments))
        log_content = manufacture.fs.getFileLines(self.test_segments)
        self.assertEqual(2, len(log_content))
        self.assertStartsWith(str(log_id), log_content[0])
        self.assertEndsWith(log_message, log_content[0])
        self.assertStartsWith(str(log_id + 1), log_content[1])
Exemplo n.º 3
0
    def test_addHandler_with_name(self):
        """
        It adds the handler and sends a notification.

        After that the handler is called on all log events.
        """
        log_handler = InMemoryHandler()
        log_entry_id = manufacture.getUniqueInteger()
        log_entry = manufacture.getUniqueString()
        callback = self.Mock()
        self.logger.subscribe('add-handler', callback)

        self.logger.addHandler(log_handler)
        self.logger.log(log_entry_id, log_entry)

        self.assertEqual(log_entry, log_handler.history[0].text)
        self.assertEqual(1, callback.call_count)
        signal = callback.call_args[0][0]
        self.assertEqual(log_handler.name, signal.name)
    def test_file_rotate_at_size_update(self):
        """
        log_file_rotate_at_size can be updated at runtime
        """
        new_value = manufacture.getUniqueInteger()
        content = (
            '[log]\n'
            'log_file_rotate_at_size: 7\n'
            )
        callback = self.Mock()
        section = self._getSection(content)
        section.subscribe('file_rotate_at_size', callback)

        section.file_rotate_at_size = new_value

        self.assertEqual(new_value, section.file_rotate_at_size)
        self.assertEqual(1, callback.call_count)
        signal = callback.call_args[0][0]
        self.assertEqual(new_value, signal.current_value)