Repository navigation
Use __name__ for loggers, per convention - #989
Conversation
Replace hard-coded logger names with __name__. For the most part this just uses the standard conventions to create the same logger hierarchy as existed before. The only real difference is that loggers created for printing during tests are no longer part of the 'tuf' hierarchy. Signed-off-by: Joshua Lock <[email protected]>
| # Set the logger and its settings. | ||
| # Note: we're configuring the top-level hierarchy for the tuf package, | ||
| # therefore we explicitly request the 'tuf' logger, rather than following | ||
| # the standard pattern of logging.getLogger(__name__) |
There was a problem hiding this comment.
We could avoid this if we move initialising the top-level logger into tuf/__init__.py, but as we will still want this module and its API to be able to configure the logger hierarchy it didn't seem particularly beneficial to make that change.
|
Hooray for passing AppVeyor tests (see #985). :) |
trishankatdatadog
left a comment
There was a problem hiding this comment.
Thanks for this much less brittle code, Joshua! 🎉
| # instead of using the standard getLogger(__name__) pattern, because the | ||
| # tests are not part of the tuf hierarchy and we are testing functionality | ||
| # of the tuf package explicitly enabled on the tuf hierarchy | ||
| logger = logging.getLogger('tuf.test_log') |
There was a problem hiding this comment.
| logger = logging.getLogger('tuf.test_log') | |
| logger = logging.getLogger(__name__) |
There was a problem hiding this comment.
Per the comment above I explicitly didn't change to __name__ here because that gives us a logger names "test_log", which isn't part of the "tuf" logger hierarchy and therefore we can not test the logging functionality in tuf.log which only affects the "tuf" logger and its children.
There was a problem hiding this comment.
Got it, somehow missed that! Curious, is this necessary for the tests to work?
There was a problem hiding this comment.
It is necessary for the tests to work.
Functions in tuf.log change logger configuration settings on the "tuf" logger and its children. Therefore if we create a logger in the test named "test_log" (via getLogger(__name__)) the tuf.log calls don't affect the logger we created (as it's not a member of the "tuf" logger hierarchy) and the tests fail:
======================================================================
FAIL: test_set_log_level (test_log.TestLog)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/joshuagl/Projects/tuf/tests/test_log.py", line 62, in test_set_log_level
self.assertTrue(logger.isEnabledFor(logging.DEBUG))
AssertionError: False is not true
woodruffw
left a comment
There was a problem hiding this comment.
Thanks for this! Should make logging control in the context of Warehouse a good deal easier 😄
lukpueh
left a comment
There was a problem hiding this comment.
LGTM. Many thanks for taking on this dull but very valuable task! :)
| <Purpose> | ||
| Write all the JSON Metadata objects to their corresponding files. | ||
| Write all the JSON Metadata objects to their corresponding files for | ||
| roles which have changed. |
Fixes issue #: N/A
Description of the changes being introduced by the pull request:
logging.getLogger(__name__).Please verify and check that the pull request fulfills the following
requirements: