-
-
Notifications
You must be signed in to change notification settings - Fork 397
The python logging module no longer seems to work properly inside a notebook #127
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
|
I've just pushed another commit which moves the tornado logging init from |
|
Thanks, I think this looks good. Typically, |
| """ Must set up the tornado logger or else tornado will call | ||
| basicConfig for the root logger which makes the root logger | ||
| go to the real sys.stderr instead of the capture streams. | ||
| This function mimics the setup of logging.basicConfig. |
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.
Can you make this docstring follow the format:
- Single line summary
- Blank line
- Paragraph with more information (optional)
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, done
|
@takluyver you're right, I've renamed the method: |
|
@takluyver yeah, that's fine. I think we have one or two other instances of |
|
OK then, I think this looks fine. Thanks @tudorprodan |
|
Welcome to the project, @tudorprodan! |
This pull request fixes this issue: jupyter/notebook#1397
For the sake of completeness, I'll repeat the issue here (edited according to the discussion on jupyter/notebook#1397).
When running the example from the python logging documentation page in a jupyter notebook, the messages go to the notebook console as opposed to the notebook's webpage output via the capture mechanism. Just create an empty notebook, run the example below, you'll see what I mean.
What should happen: The messages appear in the notebook.
What actually happens: The messages don't appear in the notebook.
The issue is caused by:
logging.basicConfig().logging.basicConfig()will then set up the root logger (logging.root) to use a defaultStreamHandler.StreamHandlerwhen not given a stream defaults tosys.stderr.sys.stderris not the ipykernel captured output yet, it will be set later.Just to be clear, this is the IOLoop on the side of the subprocess, not on the side of the jupyter server.
The tornado code that calls
basicConfigis:https://github.com/tornadoweb/tornado/blob/stable/tornado/ioloop.py#L360
I've added the
IOPubThread._setup_tornado_logger()method which will just add a defaultStreamHandlerto thetornadologger. This will stop tornado from calling basicConfig, so the actual user can configure the root logger.With this patch, the code at the beginning of this comment works as expected in a notebook.