Support for Jebena Trace ID; fix for Python2 Logging setups#19
Merged
Conversation
| # 2) fetch the root logger, and 3) if it has no handlers, call basicConfig | ||
| if sys.version_info[0] == 2: | ||
| if not len(logging.getLogger().handlers): | ||
| logging.basicConfig() |
There was a problem hiding this comment.
are we sure this is going to work? i think last time we tried basicConfig it overrode all my custom logger stuff. @jpotter
Contributor
Author
There was a problem hiding this comment.
logging.getLogger().handlers should be non-empty if you have any custom loggers installed. This code only gets triggered after a call to run_query() is triggered, so as long as you've configured your loggers before executing the client, it should be safe.
In theory. In practice, there might be something I've missed here, though -- let me know how it works for you?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This fixes #16 (for a second time) and addresses #18.
Python Logging
The issue appears to be related to python2 envs that already have logging configured. After some investigation, the cleanest way I can find to check this condition is to see if the root logger has any handlers attached to it (i.e. stream writers or file writers). If no handlers; logging not configured.
This PR updates the client to call a function,
__get_logger, that can lazy-load the logger and configure it accordingly. This allows thejebenaclientto be imported before other parts of the python system may have triggered their logging config.Jebena Trace ID
Developers wanting to fetch the Jebena Trace ID of the most recent call to
run_query()can now do so by callingjebenaclient.get_last_run_trace_id()-- simple enough. This should work after a failed GQL call as well, i.e. calling something like this:yields this -- note the very last line.