-
-
Notifications
You must be signed in to change notification settings - Fork 37
Integrate Python logging module into all .py files of Quantifying + README Update for Logging #97
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
Conversation
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.
looking good! just a few requested changes
Line 205 - changed the log so that it keeps the traceback
Line 124 - Logging statement includes traceback
Line 70 - logging statement includes traceback
Line 330 - Logging statement includes traceback
Line 541 - kept exit status (130) Line 544 - kept exit status (1) Replaced with f-strings on lines 412, 413, and 538
- Logging kept inclusion of Error (1), (130), as well as using f-string for e.code
- Logging included keeping Error (1), Error (130), and used f-string for e.code
- Logging kept the inclusion of Error (1), Error (130), and f-string for e.code
- Logging kept the inclusion of Error (1), Error (130), tracebacks, and f-string for e.code
- Kept the inclusion of (1), (130), traceback, and f-string for e.code
- Updated by including (1), (130), traceback, and f-string for e.code
- Updated logging statements to include (1), (130), traceback, and f-string for e.code
Thank you for the feedback @TimidRobot! I just updated the exception handling in all of the files (base code shown below), which 1. replaces the e.code line using an f-string instead, 2. Keeps the (130) and/or (1) in the LOG.info() statements, and 3. I made sure to include the traceback in the log statements as well. Please let me know if I need to fix anything else! if __name__ == "__main__":
# Exception Handling
try:
main()
except SystemExit as e:
LOG.error(f"System exit with code: {e.code}")
sys.exit(e.code)
except KeyboardInterrupt:
LOG.info("(130) Halted via KeyboardInterrupt.")
sys.exit(130)
except Exception:
LOG.error(f"(1) Unhandled exception: {traceback.format_exc()}")
sys.exit(1) |
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.
Please fix last f-string and resolve static analysis errors
@naishasinha don't forget to pull changes from merge conflict resolution |
@TimidRobot I believe the current static analysis errors in my version are due to the code not aligning with pre-commit, I'll fix those and also pull changes from merge conflict resolution by tonight |
…Also fixed all pre-commit issues
@TimidRobot I've fixed all the static analysis errors and have also pulled changes from merge conflict resolution! Please let me know if there's anything else I need to do. Thank you for your patience! |
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.
There's a few more static analysis errors to resolve
./dev/tools.sh
isort
Loading .env environment variables...
Skipped 1 files
black
Loading .env environment variables...
reformatted /Users/timidrobot/CreativeCommons/git/quantifying/wikipedia/wikipedia_scratcher.py
reformatted /Users/timidrobot/CreativeCommons/git/quantifying/google_custom_search/google_scratcher.py
reformatted /Users/timidrobot/CreativeCommons/git/quantifying/visualization/visualization_engineering.ipynb
All done! ✨ 🍰 ✨
3 files reformatted, 15 files left unchanged.
flake8
Loading .env environment variables...
./deviantart/deviantart_scratcher.py:7:1: F401 'datetime as dt' imported but unused
./metmuseum/metmuseum_scratcher.py:8:1: F401 'datetime as dt' imported but unused
./vimeo/vimeo_scratcher.py:11:1: F401 'datetime as dt' imported but unused
./wikicommons/wikicommons_scratcher.py:8:1: F401 'datetime as dt' imported but unused
./youtube/youtube_scratcher.py:8:1: F401 'datetime as dt' imported but unused
or
pipenv run pre-commit run -a
Loading .env environment variables...
check for added large files..............................................Passed
check python ast.........................................................Passed
check for case conflicts.................................................Passed
check docstring is first.................................................Passed
check that executables have shebangs.....................................Passed
check json...............................................................Passed
check for merge conflicts................................................Passed
check toml...............................................................Passed
check yaml...............................................................Passed
detect destroyed symlinks................................................Passed
fix end of files.........................................................Passed
mixed line ending........................................................Passed
trim trailing whitespace.................................................Failed
- hook id: trailing-whitespace
- exit code: 1
- files were modified by this hook
Fixing wikipedia/wikipedia_scratcher.py
Fixing google_custom_search/google_scratcher.py
Black....................................................................Passed
Flake8...................................................................Failed
- hook id: flake8
- exit code: 1
deviantart/deviantart_scratcher.py:7:1: F401 'datetime as dt' imported but unused
wikicommons/wikicommons_scratcher.py:8:1: F401 'datetime as dt' imported but unused
metmuseum/metmuseum_scratcher.py:8:1: F401 'datetime as dt' imported but unused
youtube/youtube_scratcher.py:8:1: F401 'datetime as dt' imported but unused
vimeo/vimeo_scratcher.py:11:1: F401 'datetime as dt' imported but unused
isort....................................................................Passed
@TimidRobot Fixed! |
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.
good work!
Fixes
Fixes #85 by @naishasinha
Description
This pull request incorporates an efficient method to use logging within all Python files, keeping in mind the possibility of shared modules. I've also added an update to the "Resources" section in the README with a link to the logging section of the Python docs that other contributors can reference to if they need help with any aspect of the module.
In addition to replacing all the current print() statements with logging, I've also added descriptor LOG.info() statements within the start of each function so that when being logged in the terminal, it's easier for the contributor to understand which function is being debugged.
Technical details
Multiple calls to LOG (which is a variable stored from getLogger()) will return a reference to the same logger object, both within the same module as well as across modules
This was the general logger setup for all files. As it is consistent among all files, it makes it easier to access and reference among shared modules:
Other notes:
The Handler object is responsible for sending the logs to different destinations, and the Formatter object determines the order, structure, and contents of the log message. Having these objects will make it easier to log between shared modules.
Checklist
Update index.md
).main
ormaster
).visible errors.
Developer Certificate of Origin
For the purposes of this DCO, "license" is equivalent to "license or public domain dedication," and "open source license" is equivalent to "open content license or public domain dedication."
Developer Certificate of Origin