Skip to content

Commit

Permalink
add no cache get_logger test
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-jopel committed Oct 13, 2024
1 parent b24fcc9 commit 2b7835c
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions opentelemetry-sdk/tests/logs/test_logger_provider_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,41 @@ def test_get_logger_multiple_loggers(self):
logger.warning("test message")

self.assertEqual(num_loggers, len(logger_cache))

def test_provider_get_logger_no_cache(self):
_, logger_provider = set_up_logging_handler(level=logging.DEBUG)
# pylint: disable=protected-access
logger_cache = logger_provider._logger_cache

logger_provider.get_logger(
name="test_logger",
version="version",
schema_url="schema_url",
attributes={"key": "value"},
)

# Ensure logger is not cached if attributes is set
self.assertEqual(0, len(logger_cache))

def test_provider_get_logger_cached(self):
_, logger_provider = set_up_logging_handler(level=logging.DEBUG)
# pylint: disable=protected-access
logger_cache = logger_provider._logger_cache

logger_provider.get_logger(
name="test_logger",
version="version",
schema_url="schema_url",
)

# Ensure only one logger is cached
self.assertEqual(1, len(logger_cache))

logger_provider.get_logger(
name="test_logger",
version="version",
schema_url="schema_url",
)

# Ensure only one logger is cached
self.assertEqual(1, len(logger_cache))

0 comments on commit 2b7835c

Please sign in to comment.