Skip to content
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

Avoid duplicate log messages in Jupyter #1225

Merged
merged 1 commit into from
Oct 31, 2023

Conversation

lucas-flexcompute
Copy link
Collaborator

When a rich console is created within a jupyter notebook, it autodetects the environment and outputs log messages by default, which ends up duplicating our messages, because we already have a standard output by default. A flag can be set to false to inhbit the autodetection.

@lucas-flexcompute
Copy link
Collaborator Author

To test this out, this simple script running as a jupyter cell, ipython session, or a standalone python file should demonstrate the issue:

import tidy3d as td
td.set_logging_file("logfile.log")
td.log.warning("Issue some warning")

@tylerflex
Copy link
Collaborator

Thanks Lucas, I'm not sure I could detect the issue when I tried it in ipython. Could you explain? and also add this to the changelog as well? (just updated on pre/2.5, so you'll want to pull)

@lucas-flexcompute
Copy link
Collaborator Author

lucas-flexcompute commented Oct 30, 2023 via email

@lucas-flexcompute
Copy link
Collaborator Author

So here is the issue better explained. In the python/ipython terminal:
20231031-073246

And in Jupyter:
20231031-073304

The second message is a "helper" function of the rich console, which also prints log file messages when it detects the jupyter environment. This is fixed by setting the flag force_jupyter=False when creating a rich console for file output only.

@tylerflex
Copy link
Collaborator

Looks good, feel free to merge after adding a changelog under "fixed". thanks!

When a rich console is created within a jupyter notebook, it autodetects
the environment and outputs log messages by default, which ends up
duplicating our messages, because we already have a standard output by
default. A flag can be set to false to inhbit the autodetection.

Signed-off-by: Lucas Heitzmann Gabrielli <lucas@flexcompute.com>
@lucas-flexcompute lucas-flexcompute merged commit c328507 into pre/2.5 Oct 31, 2023
1 of 13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants