-
Notifications
You must be signed in to change notification settings - Fork 9
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
Improve logging #80
Improve logging #80
Conversation
Codecov Report
@@ Coverage Diff @@
## master #80 +/- ##
========================================
+ Coverage 98.1% 98.5% +0.4%
========================================
Files 8 8
Lines 382 425 +43
========================================
+ Hits 375 419 +44
+ Misses 7 6 -1
|
@jayqi Looks very helpful! I installed it from the new branch and had no issues. A couple questions for my own understanding:
|
Yes.
No, this is mainly just for completeness. You could always invoke nbautoexport as a library or (more commonly) with the CLI command. This just makes sure the logs behave in ways that Python devs expect if you were to do those things.
You can run |
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.
This is excellent! One tiny tiny suggestion related to what is logged at specific levels during installation. Here's the outputs for different possible states at different log levels:
Not already installed:
(nbautoexport-dev) ➜ nbautoexport git:(74-improve-logging) nbautoexport install
nbautoexport post-save hook successfully installed with Jupyter.
If a Jupyter server is already running, you will need to restart it for nbautoexport to work.
(nbautoexport-dev) ➜ nbautoexport git:(74-improve-logging) nbautoexport install -v
2021-10-01 09:50:44,793 - nbautoexport - INFO - Installing post-save hook.
2021-10-01 09:50:44,793 - nbautoexport - INFO - nbautoexport post-save hook installed.
nbautoexport post-save hook successfully installed with Jupyter.
If a Jupyter server is already running, you will need to restart it for nbautoexport to work.
(nbautoexport-dev) ➜ nbautoexport git:(74-improve-logging) nbautoexport install -vv
2021-10-01 09:51:06,471 - nbautoexport - DEBUG - Detected existing Jupyter configuration at /home/robert/.jupyter/jupyter_notebook_config.py
2021-10-01 09:51:06,471 - nbautoexport - INFO - Installing post-save hook.
2021-10-01 09:51:06,471 - nbautoexport - INFO - nbautoexport post-save hook installed.
nbautoexport post-save hook successfully installed with Jupyter.
If a Jupyter server is already running, you will need to restart it for nbautoexport to work.
Already installed:
(nbautoexport-dev) ➜ nbautoexport git:(74-improve-logging) nbautoexport install
nbautoexport post-save hook successfully installed with Jupyter.
If a Jupyter server is already running, you will need to restart it for nbautoexport to work.
(nbautoexport-dev) ➜ nbautoexport git:(74-improve-logging) nbautoexport install -v
nbautoexport post-save hook successfully installed with Jupyter.
If a Jupyter server is already running, you will need to restart it for nbautoexport to work.
(nbautoexport-dev) ➜ nbautoexport git:(74-improve-logging) nbautoexport install -vv
2021-10-01 09:49:21,364 - nbautoexport - DEBUG - Detected existing Jupyter configuration at /home/robert/.jupyter/jupyter_notebook_config.py
2021-10-01 09:49:21,365 - nbautoexport - DEBUG - Detected existing nbautoexport post-save hook.
2021-10-01 09:49:21,366 - nbautoexport - DEBUG - Existing post-save hook is version 0.3.1+32.g5d71683
2021-10-01 09:49:21,366 - nbautoexport - DEBUG - No changes made.
nbautoexport post-save hook successfully installed with Jupyter.
If a Jupyter server is already running, you will need to restart it for nbautoexport to work.
Already installed different version:
(nbautoexport-dev) ➜ nbautoexport git:(74-improve-logging) nbautoexport install
nbautoexport post-save hook successfully installed with Jupyter.
If a Jupyter server is already running, you will need to restart it for nbautoexport to work.
(nbautoexport-dev) ➜ nbautoexport git:(74-improve-logging) ✗ nbautoexport install -v
2021-10-01 09:56:38,983 - nbautoexport - INFO - Updating nbautoexport post-save hook with version 0.3.1+32.g5d71683...
2021-10-01 09:56:38,984 - nbautoexport - INFO - nbautoexport post-save hook installed.
nbautoexport post-save hook successfully installed with Jupyter.
If a Jupyter server is already running, you will need to restart it for nbautoexport to work.
(nbautoexport-dev) ➜ nbautoexport git:(74-improve-logging) ✗ nbautoexport install -vv
2021-10-01 09:56:51,727 - nbautoexport - DEBUG - Detected existing Jupyter configuration at /home/robert/.jupyter/jupyter_notebook_config.py
2021-10-01 09:56:51,727 - nbautoexport - DEBUG - Detected existing nbautoexport post-save hook.
2021-10-01 09:56:51,729 - nbautoexport - DEBUG - Existing post-save hook is version 0.2.1+32.g5d71683
2021-10-01 09:56:51,729 - nbautoexport - INFO - Updating nbautoexport post-save hook with version 0.3.1+32.g5d71683...
2021-10-01 09:56:51,730 - nbautoexport - INFO - nbautoexport post-save hook installed.
nbautoexport post-save hook successfully installed with Jupyter.
If a Jupyter server is already running, you will need to restart it for nbautoexport to work.
For the "Already installed" state, the output for no verbosity flag and -v
are the same. Besides that, as a user, I might expect that nbautoexport install -v
would tell me whether it's installing or whether it detects an existing installation. My suggestion would just be to promote:
logger.debug("Detected existing nbautoexport post-save hook.") |
nbautoexport/nbautoexport/jupyter_config.py
Line 116 in 5d71683
logger.debug("No changes made.") |
from debug
to info
. Then the output for nbautoexport install -v
would be:
(nbautoexport-dev) ➜ nbautoexport git:(74-improve-logging) nbautoexport install -v
2021-10-01 09:49:21,364 - nbautoexport - INFO - Detected existing Jupyter configuration at /home/robert/.jupyter/jupyter_notebook_config.py
2021-10-01 09:49:21,366 - nbautoexport - INFO - No changes made.
nbautoexport post-save hook successfully installed with Jupyter.
If a Jupyter server is already running, you will need to restart it for nbautoexport to work.
190d083
to
1d9c13b
Compare
Thanks for the review @r-b-g-b, I incorporated your suggestions. |
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.
Awesome!
Improves logging for nbautoexport to make things easier to troubleshoot.
There are three scenarios of use, each of which will have logging that works differently, in order of likely relevance to users:
"nbautoexport"
is used, and configured with a stream handler that will print to console. The--verbose/-v
flag is now a counter instead of a boolean flag.typer.echo
statements and sets log level to WARNING.-v
is INFO log level.-vv
is DEBUG log level."nbautoexport"
is used, and set with a null handler. This is best practice so that the nbautoexport logger will inherit the users' desired configuration from the root logger.One change looking for feedback:
Examples of logs from Jupyter Lab
Successful startup
Jupyter Lab
Jupyter Notebook
Failed startup
Successful export
Jupyter Lab
Jupyter Notebook
.nbautoexport validation error
Export with debug mode
Example of CLI verbosity levels
Example of importing as library
demo_logging.py
Output: