Example #1
0
    def test_filter_default_component(self):
        component_logger = structuredlog.StructuredLogger(self.logger.name,
                                                          "test_component")

        self.logger.debug("Test")
        self.assertFalse(self.handler.empty)
        self.assert_log_equals({"action": "log",
                                "level": "DEBUG",
                                "message": "Test"})

        self.logger.component_filter = handlers.LogLevelFilter(lambda x:x, "info")

        self.logger.debug("Test 1")
        self.assertTrue(self.handler.empty)

        component_logger.debug("Test 2")
        self.assertFalse(self.handler.empty)
        self.assert_log_equals({"action": "log",
                                "level": "DEBUG",
                                "message": "Test 2",
                                "component": "test_component"})

        self.logger.component_filter = None

        self.logger.debug("Test 3")
        self.assertFalse(self.handler.empty)
        self.assert_log_equals({"action": "log",
                                "level": "DEBUG",
                                "message": "Test 3"})
Example #2
0
    def setup_server_logging(self):
        server_logger = get_default_logger(component="wptserve")
        assert server_logger is not None
        log_filter = handlers.LogLevelFilter(lambda x: x, "info")
        # Downgrade errors to warnings for the server
        log_filter = LogLevelRewriter(log_filter, ["error"], "warning")
        server_logger.component_filter = log_filter

        serve.logger = server_logger
        #Set as the default logger for wptserve
        serve.set_logger(server_logger)
Example #3
0
    def setup_server_logging(self):
        server_logger = get_default_logger(component="wptserve")
        assert server_logger is not None
        log_filter = handlers.LogLevelFilter(lambda x:x, "info")
        # Downgrade errors to warnings for the server
        log_filter = LogLevelRewriter(log_filter, ["error"], "warning")
        server_logger.component_filter = log_filter

        try:
            #Set as the default logger for wptserve
            serve.set_logger(server_logger)
            serve.logger = server_logger
        except Exception:
            # This happens if logging has already been set up for wptserve
            pass