-
Notifications
You must be signed in to change notification settings - Fork 13
Basic logging w/ interface to methods' verbose kwarg #34
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
Basic logging w/ interface to methods' verbose kwarg #34
Conversation
|
(Expecting the Mac OS Actions test jobs to fail, as there are issues in the dependency setup on |
|
@davidhassell: (for after the long weekend if you have started yours) I thought I'd let you see this at this nearly-done stage in case you have any comments on the implementation & approach, etc., & so you can become familiar with how the logging will work in code terms. If you want to do a formal code review, that's fine too, in which case just assign yourself. |
Note: levels are being chosen leniently, because there will often be data quality or CF-compliance issues that do not prevent successful operations, & we don't want to spam users with these messages unless they specify the highest log severity levels.
This is to avoid excess output from warnings and errors set up deliberately for testing.
|
Hi Sadie, I wonder if the What do you think? |
|
Should we take this opportunity to rename the package level functions to lower case: That said, these functions do have something in common, which the other package level functions don't have, in that they are all about the setting of global constants. I don't mind either way - what do you think? |
|
Thanks for your feedback comments @davidhassell. In response:
Ah yes, that's a very good idea! There were a few methods you mentioned &/or I noticed have some levelling aspect already (e.g.
I can change from value to identity check so True is distinguished, & I'll implement it as you suggest in your comment.
It would be good to do this, & I am happy to here, but maybe to avoid cluttering this PR I can do this as follow-on work? I was thinking of the cf-python Issue NCAS-CMS/cf-python#70 which would be an ideal place to do the renaming for cf-python, but best do that after the logging is in so that can be included. And best do the renaming on cfdm & cf-python together. Either way, I think I can get all that in for the next release set. Now I am back from leave I will prioritise getting this PR done including to extend it according to your feedback, but that shouldn't be too difficult or time-consuming since the bulk of the code is there & just needs tweaking. Also looking at my changes afresh after my break, I am thinking maybe I should create a test case ( |
This is in response to discussion yesterday on the status of the logging in practice, where it was agreed that error cases are handled adequately by standard exceptions but that it would be useful to have a further informational level. Note: the API ref docs & possibly some other aspects of the PR NCAS-CMS#34 still need to be amended to reflect these level changes. This will be addressed in the next commit.
This is because it now configures a mix of severity & verbosity, so the old name may be misleading or confusing. Plus, the new name is shorter so easier to type.
|
Reviewing aids:
|
Note: this includes a name change for the old '_reset_log_severity_level' function, to the above, since (despite being intended as private) it was no longer accurately described, either resetting the level which is in fact a mixture of severity & verbosity, or disabling the logging which doesn't influence the level. The term 'emergence' covers the various levels and disable capability.
|
Tests added & including these the local test suite passes, both when running the relevant tests individually & as part of the full test suite, which is notable because I had to make a few tweaks mainly to the I want to check the GH Actions suite results. The Mac OS jobs may fail due to platform-specific unrelated issues that have been cropping up and I need to look into, so just looking for an Ubuntu job pass. The Actions workflow would have triggered itself as far as I know, not sure why it isn't running the checks. I'll try a close & re-open to force the triggering. One conflict present has been resolved, so ready to merge once the Actions test suite job passes. |
|
All test jobs passed 🎉! It looks like the previously-observed Mac OS job issues are intermittent. I will investigate them in due course, but I'm glad they haven't cropped up here so I can be confident everything does as it should on that platform. @davidhassell I am merging this now. Thanks for your comments. As you suggest, levels attached to certain messages may not be the most appropriate but we can easily tweak the levels of any message as we attune to the logging system & outputs. It is just a case of changing a call from, e.g, I will move the noted follow-in work (see 'Post-PR work' in the opening comment) to its own Issue, but it should wait at least until the equivalent basic logging has been added to |
|
Great - thank you! I shall update my my fork. |
Resolves #31. This sets up minimal logging to delegate all applicable library messages to the
loggingmodule, such that they emerge as before by default, but there is new functionality in that they can be filtered out by severity level via a configurable global log severity level addressing the root logger, however theverbosekeyword argument in a method will behave as before by overriding the log level.Implementation
The main code changes here to achieve the above are:
__init__.py(if we add further logging configuration, we should move this to a dedicated module e.g.logging-config.py);[now renamed simplycfdm.LOG_SEVERITY_LEVELcfdm.LOG_LEVELfor clarity to reflect that the levels are a mixture of verbosity- & severity- based] to change the minimal level at which log messages emerge, beingWARNINGby default:WARNING,INFO, or instead an integer from1 through to 5[now -1 to 3 in a revised schema - see later comment] mapped to those, which is easier for users to recall, though less explicit;_manage_log_level_via_verbositywhich provides the interface with decorated methods'verbosekeyword argument, such that, as agreed, ifverboseis:True: will display all log messages from that method & any method it calls;None, as is now the default for all such methods: will use the global log severity level to determine which messages to display so some at lower levels can be filtered out if configured as such;False: will not display any log messages from that method or any method it calls.cfdm.LOG_LEVELfor increased granularity of per-function verbosity control, see Basic logging w/ interface to methods' verbose kwarg #34 (comment) though note we decided on a different schema, as aboveif verbose: print(<message>)statements being changed tolog.<level>(<message>)messages, where the conditional onverboseis no longer required as the decorator handles the equivalent logic (& more).Work still TODO for this PR
If I have missed anything, let me know! But at the least I still want to:
info;verbosekeyword argument in a new sub-section of the docs;verbosekwargs to indicate the interface with the log severity level;Post-PR work
pprint.pformatinnetcdfread.py).