Beispiel #1
0
    def test_emit_message_from_definition_bad_interpolation(self):
        """
        When wrong data is provided the an additional message is logged
        together with the non-interpolated message.
        """
        handler = EventsHandler()
        content = '''
            {
            "groups" : {
                "group": { "description": "something"}
                },
            "events" : {
                "100": {
                    "message": "100 %(unknown_data)s some message",
                    "groups": ["group"],
                    "description": "",
                    "version_removed": "",
                    "version_added": "",
                    "details": "",
                    "data": ""
                    }
                }
            }
            '''
        definitions = manufacture.makeEventsDefinition(content=content)
        log_configuration_section = manufacture.makeLogConfigurationSection()
        handler.configure(
            definitions=definitions,
            log_configuration_section=log_configuration_section)

        handler.emit('100', data={'other': u'dontcare'})

        self.assertLog(1025)
        self.assertLog(100, regex='100 %\(unknown_data\)s some message')
Beispiel #2
0
    def test_emit_message_from_definition_no_data(self):
        """
        If not message was defined for emit, the message from event definition
        will be used.

        When no data is provided the string will not be interpolated.
        """
        handler = EventsHandler()
        content = '''
            {
            "groups" : {
                "group": { "description": "something"}
                },
            "events" : {
                "100": {
                    "message": "100 %(replace)s some message",
                    "groups": ["group"],
                    "description": "",
                    "version_removed": "",
                    "version_added": "",
                    "details": "",
                    "data": ""
                    }
                }
            }
            '''
        definitions = manufacture.makeEventsDefinition(content=content)
        log_configuration_section = manufacture.makeLogConfigurationSection()
        handler.configure(
            definitions=definitions,
            log_configuration_section=log_configuration_section)

        handler.emit('100', data={'replace': 'test'})

        self.assertLog(100, regex="100 test some m")
Beispiel #3
0
    def test_emit_message_from_definition_with_data(self):
        """
        When data is provided the message will be interpolated based on
        data and event_definition.
        """
        handler = EventsHandler()
        content = '''
            {
            "groups" : {
                "group": { "description": "something"}
                },
            "events" : {
                "100": {
                    "message": "100 %(data)s some message",
                    "groups": ["group"],
                    "description": "",
                    "version_removed": "",
                    "version_added": "",
                    "details": "",
                    "data": ""
                    }
                }
            }
            '''
        definitions = manufacture.makeEventsDefinition(content=content)
        log_configuration_section = manufacture.makeLogConfigurationSection()
        handler.configure(
            definitions=definitions,
            log_configuration_section=log_configuration_section)

        data_string = manufacture.getUniqueString()
        handler.emit('100', data={'data': data_string})

        self.assertLog(100, regex="100 " + data_string + " some m")
Beispiel #4
0
    def _getConfiguration(self, content=None):

        if not content:
            content = (
                '[log]\n'
                'log_file: Disabled\n'
                )
        proxy = manufacture.makeFileConfigurationProxy(
            content=content, defaults=LOG_SECTION_DEFAULTS)
        return manufacture.makeLogConfigurationSection(proxy=proxy)
 def _getSection(self, content=None):
     """
     Return a log configuration section.
     """
     if content is None:
         content = (
             '[log]\n'
             'log_file: Disable\n'
             )
     proxy = manufacture.makeFileConfigurationProxy(
         content=content, defaults=LOG_SECTION_DEFAULTS)
     return manufacture.makeLogConfigurationSection(proxy=proxy)
Beispiel #6
0
    def test_removeConfiguration(self):
        """
        EventsHandler configurations can be removed using removeConfiguration.
        """
        handler = EventsHandler()
        definitions = manufacture.makeEventsDefinition()
        log_configuration_section = manufacture.makeLogConfigurationSection()
        handler.configure(
            definitions=definitions,
            log_configuration_section=log_configuration_section)
        self.assertTrue(handler.configured)

        handler.removeConfiguration()

        self.assertFalse(handler.configured)
Beispiel #7
0
    def test_configure(self):
        """
        EventsHandler can be configured.
        """
        handler = EventsHandler()
        definitions = manufacture.makeEventsDefinition()
        log_configuration_section = manufacture.makeLogConfigurationSection()

        handler.configure(
            definitions=definitions,
            log_configuration_section=log_configuration_section)

        self.assertTrue(handler.configured)
        self.assertIsNotNone(handler.definitions)
        self.assertEqual(
            [CONFIGURATION_ALL_LOG_ENABLED_GROUPS], handler.enabled_groups)
Beispiel #8
0
    def test_emit_with_all(self):
        """
        When 'all' group is enabled, logs will be enabled even if their
        groups is not explicitly enabled.
        """
        handler = EventsHandler()
        content = '''
            {
            "groups" : {
                "disabled": { "description": ""}
                },
            "events" : {
                "100": {
                    "message": "some message",
                    "groups": ["disabled"],
                    "description": "",
                    "version_removed": "",
                    "version_added": "",
                    "details": "",
                    "data": ""
                    },
                "101": {
                    "message": "other message",
                    "groups": ["disabled"],
                    "description": "",
                    "version_removed": "",
                    "version_added": "",
                    "details": "",
                    "data": ""
                    }
                }
            }
            '''
        definitions = manufacture.makeEventsDefinition(content=content)
        log_configuration_section = manufacture.makeLogConfigurationSection()
        log_configuration_section.enabled_groups = [
            CONFIGURATION_ALL_LOG_ENABLED_GROUPS]
        handler.configure(
            definitions=definitions,
            log_configuration_section=log_configuration_section)

        handler.emit('101', message='101some message')
        handler.emit('100', message='100some message')

        self.assertLog(101, regex="101some m")
        self.assertLog(100, regex="100some m")
Beispiel #9
0
    def test_emit_unknown_id(self):
        """
        Emitting an event with unknown ID will log an error containing
        the text of the unknown id.
        """
        handler = EventsHandler()
        message = u'Some message ' + manufacture.getUniqueString()
        definitions = manufacture.makeEventsDefinition()
        log_configuration_section = manufacture.makeLogConfigurationSection()
        handler.configure(
            definitions=definitions,
            log_configuration_section=log_configuration_section,
            )

        handler.emit(u'100', message=message)

        self.assertLog(
            1024, regex='Unknown event with id "100"')
Beispiel #10
0
    def test_emit_with_configuration(self):
        """
        If handler is configured, the logs can be filterd.
        """
        handler = EventsHandler()
        content = '''
            {
            "groups" : {
                "enabled": { "description": ""},
                "disabled": { "description": ""}
                },
            "events" : {
                "100": {
                    "message": "some message",
                    "groups": ["enabled"],
                    "description": "",
                    "version_removed": "",
                    "version_added": "",
                    "details": "",
                    "data": ""
                    },
                "101": {
                    "message": "other message",
                    "groups": ["disabled"],
                    "description": "",
                    "version_removed": "",
                    "version_added": "",
                    "details": "",
                    "data": ""
                    }
                }
            }
            '''
        definitions = manufacture.makeEventsDefinition(content=content)
        log_configuration_section = manufacture.makeLogConfigurationSection()
        log_configuration_section.enabled_groups = ['enabled']
        handler.configure(
            definitions=definitions,
            log_configuration_section=log_configuration_section)

        handler.emit('101', message='101some message')
        handler.emit('100', message='100some message')

        self.assertLog(100, regex="100some m")