Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Implement loggers #72
Implement loggers #72
Changes from 2 commits
51aa9c8
bde7e86
62457a8
e25b3f5
e8129fb
a8c5d91
e8e98f7
cfa0218
bb9828b
cdebee2
acd1079
b1ebd0c
2ae41da
f736ee7
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
Move this call to each function that requires logging, as it leads to unpredictable behavior when changing the verbosity using
SWMMANYWHERE_VERBOSE
env var. This happens because when you call it here in theutils
module, you read theSWMMANYWHERE_VERBOSE
variable only when the package is being loaded. So, if a user setsSWMMANYWHERE_VERBOSE
after loading the package, it won't work.Essentially, this works:
but this doesn't work as expected:
But if you call it within functions, it will always work correctly, regardless of the import order.
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 tidied it all up a bit and added some tests (for these - see
SWMManywhere/tests/test_logging.py
Line 32 in a8c5d91
and
SWMManywhere/tests/test_logging.py
Line 45 in a8c5d91
).
Simply importing
logger
and settinglogger.enable('swmmanywhere')
orlogger.disable('swmmanywhere')
seems to work fine globally regardless of when the import happens - if you can write a test that breaks it then I'll reconsider ;)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.
I find it easier and more flexible to use an env variable to control the verbosity rather than importing a function. You can set it from the command-line, or anywhere in code, without having to know the logger syntax.
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 this is a good argument for global variables!
So I have added a filter that enables control of verbosity through globals, but also continues use of a global logger.
@cheginit and @dalonsoa - is this actually a good idea or am I opening up for a world of hurt?
Otherwise I will just go with @cheginit 's initial suggestion and import the logger locally each time it is used, still controlling it through globals.
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.
It looks good to me. The dynamic filter seems to enable the best of both worlds.
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.
Yeah, LGTM.