Ejemplo n.º 1
0
    def test_logger_init(self):
        """
        When creating a new DDLogger
            Has the same interface as logging.Logger
            Configures a defaultdict for buckets
            Properly configures the rate limit
        """
        # Create a logger
        log = DDLogger('test.logger')

        # Ensure we set the name and use default log level
        self.assertEqual(log.name, 'test.logger')
        self.assertEqual(log.level, logging.NOTSET)

        # Assert DDLogger default properties
        self.assertIsInstance(log.buckets, dict)
        self.assertEqual(log.rate_limit, 60)

        # Assert manager and parent
        # DEV: Parent is `None` because `manager._findParents()` doesn't get called
        #      unless we use `get_logger` (this is the same behavior as `logging.getLogger` and `Logger('name')`)
        self.assertEqual(log.manager, self.manager)
        self.assertIsNone(log.parent)

        # Override rate limit from environment variable
        with self.override_env(dict(DD_LOGGING_RATE_LIMIT='10')):
            log = DDLogger('test.logger')
            self.assertEqual(log.rate_limit, 10)

        # Set specific log level
        log = DDLogger('test.logger', level=logging.DEBUG)
        self.assertEqual(log.level, logging.DEBUG)
Ejemplo n.º 2
0
    def test_logger_deprecated_rate_limit(self):
        with self.override_env(dict(DD_LOGGING_RATE_LIMIT="10")), warns(RemovedInDDTrace10Warning):
            log = DDLogger("test.logger")
            self.assertEqual(log.rate_limit, 10)

        # Ensure correct precedence
        with self.override_env(dict(DD_LOGGING_RATE_LIMIT="10", DD_TRACE_LOGGING_RATE="20")):
            log = DDLogger("test.logger")
            self.assertEqual(log.rate_limit, 20)