-
-
Notifications
You must be signed in to change notification settings - Fork 33.9k
bpo-30962: Add caching to Logger.isEnabledFor() #2752
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
26a8efc
aeec4d9
7deaaab
f3b23ad
d10e0e2
d6d28ec
11fee13
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4406,6 +4406,29 @@ def test_basic(self): | |
| self.assertTrue(found, msg=msg) | ||
|
|
||
|
|
||
| class CachingTest(BaseTest): | ||
| def test_caching(self): | ||
| root = self.root_logger | ||
| level1 = logging.getLogger("abc") | ||
|
||
| level2 = logging.getLogger("abc.def") | ||
|
|
||
| root.setLevel(logging.ERROR) | ||
| self.assertEqual(level2._cache, {}) # Cache is empty | ||
|
|
||
| self.assertTrue(level2.isEnabledFor(logging.ERROR)) | ||
| self.assertEqual(level2._cache, {logging.ERROR: True}) # Cache is populated | ||
|
||
| self.assertEqual(root._cache, {}) # Root cache is empty | ||
| self.assertTrue(level2.isEnabledFor(logging.ERROR)) | ||
|
|
||
| level1.setLevel(logging.CRITICAL) | ||
| self.assertEqual(level2._cache, {}) # Cache is empty | ||
| self.assertEqual(root._cache, {}) # Root cache is empty | ||
|
|
||
| self.assertFalse(level2.isEnabledFor(logging.ERROR)) | ||
| self.assertTrue(root.isEnabledFor(logging.ERROR)) | ||
| self.assertEqual(root._cache, {logging.ERROR: True}) # Root cache is populated | ||
|
|
||
|
||
|
|
||
| class MiscTestCase(unittest.TestCase): | ||
| def test__all__(self): | ||
| blacklist = {'logThreads', 'logMultiprocessing', | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could add this to an existing test case class rather than adding a separate class just for this one method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I'll move it to the LoggerTest class