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

difficulty to read logs with Jupyter (VSCode Dark theme) and new logging #1733

Closed
Tracked by #2928
Debbby57 opened this issue Jul 28, 2022 · 16 comments
Closed
Tracked by #2928

Comments

@Debbby57
Copy link

Description

I'm working on VSCode, and I custom my vscode with the Dark+ color theme. When I use interactive python to work it's really diffcult to read logs because of colors. I need to select them to be able to read them correctly. I notice that the colors are slightly different in interactive python and in terminal.

Context

Steps to Reproduce

  1. use Vscode and Dark+ color theme
  2. install kedro 0.18.2
  3. some code like :
from pathlib import Path
from kedro.framework.session import KedroSession
from kedro.framework.startup import bootstrap_project
my_path = Path(__file__).resolve().parent.parent 
metadata = bootstrap_project(my_path)
session = KedroSession.create(metadata.package_name, project_path=my_path)
local_context = session.load_context()
my_data= local_context.catalog.load("my_partitioned_data")

you will have :
image

my_data.items()

you will have :
image

Expected Result

I would like to have readable logs.

Actual Result

logs are difficulty to read.

Your Environment

  • Kedro version used (pip show kedro or kedro -V): 0.18.2
  • Python version used (python -V): 3.9.13
  • Operating system and version: linux and VSCode with Dark+ theme

thank you for your help :)

@datajoely
Copy link
Contributor

Can you run the following command python -m rich.logging on your terminal?

image

I'm using the Dark+ them with Zsh on my end and the logs look like they do above?

@Debbby57
Copy link
Author

thank you for your reply.
I have no problem with my logs in terminal. When I run your command on terminal I have the same logs as you. I only have those color problems when I use the interactive python window (Jupyter) of VSCode. Sorry if my issue wasn't explicit :/

@datajoely
Copy link
Contributor

@noklam maybe let's group this under the similar databricks issue?

@noklam
Copy link
Contributor

noklam commented Jul 28, 2022

I get a clear log with it on the VSCode Jupyter
image

But with session.run() I get this, I don't think we have manually configured these colors for INFO/DEBUG etc, so it may be something special with the Jupyter extension tricking rich. @AhdraMeraliQB any idea about this?

image

Supplement a bit more, it is recognized correctly as Jupyter with the VSCode extension.
image

@noklam
Copy link
Contributor

noklam commented Jul 28, 2022

@datajoely Do you think this is a rich problem? This is the minimal example that I can produce.

image

import rich
rich.pretty.install()
console = rich.get_console()
console

@datajoely
Copy link
Contributor

Can we get anywhere with this color_system piece?
https://rich.readthedocs.io/en/stable/console.html#color-systems

@noklam
Copy link
Contributor

noklam commented Jul 28, 2022

@datajoely Doesn't seem to have any effect. I think it's likely some hook buried in rich.pretty.install()

@datajoely
Copy link
Contributor

Maybe we should provide a readymade console to the install method?

https://github.com/Textualize/rich/blob/2ee992b17ef5ff3c34f89545b0d57ad4690a64fc/rich/pretty.py#L198

@noklam
Copy link
Contributor

noklam commented Jul 28, 2022

@datajoely Did you get any working example that has effect on it? I try to play around with the config but it doesn't change the output style at all.

There is another get_console call down below
https://github.com/Textualize/rich/blob/2ee992b17ef5ff3c34f89545b0d57ad4690a64fc/rich/pretty.py#L256

@datajoely
Copy link
Contributor

@antonymilne antonymilne changed the title difficulty to read logs with interactive python (VSCode Dark theme) and new logging difficulty to read logs with Jupyter (VSCode Dark theme) and new logging Jul 29, 2022
@antonymilne
Copy link
Contributor

antonymilne commented Jul 29, 2022

I can confirm this is a problem with Jupyter specifically (not IPython) and not limited to VSCode. It boils down to how rich handles the colour scheme.

Here's what I get with kedro ipython and session.run():
image

Here's what I get with kedro jupyter lab and session.run():
image

The colour schemes used here are clearly a bit different. The one I see in Jupyter is the same as the one that you see in VSCode Jupyter also.

Ultimately this is due the fact that rich seems to render logging using a slightly different colour scheme in Jupyter compared to on the console. e.g. using this example from the docs in a plain (non-Kedro) Jupyter notebook. The INFO is in the dark blue rather than the light blue:
image
Note that rich.pretty.install is not what gives this colour scheme this since the above notebook did not have that run.

So I think what we're seeing here is nothing in particular to do with the Kedro setup but the fact that rich uses a different colour scheme for logging in Jupyter vs. on the console. I don't know if that's deliberate or not - we should ask there.

@noklam
Copy link
Contributor

noklam commented Jul 29, 2022

@AntonyMilneQB I agree this is more a rich issue and we should ask there.

But I think rich.pretty.install did play some roles here. It could be both the RichHandler and the __repr__

This example should be enough to prove this.
image

@antonymilne
Copy link
Contributor

antonymilne commented Jul 29, 2022

Ah yes, what I meant to say was that the rich.pretty.install shouldn't affect the colour of the log messages. As you show, it affects the appearance of the REPL, which is less important but still doesn't seem to be handled nicely by rich in Jupyter when there's not a light background.

Again, this works fine on IPython and is just a problem on Jupyter:
image

So on my dark terminal background rich knows to adapt the text colour to be light. Ideally in Jupyter it would work the same way rather than rendering black text on a dark background.

@noklam
Copy link
Contributor

noklam commented Aug 16, 2022

I'll add my own experience, I just install jupyterthemes for Jupyter Notebook and it doesn't work well with the dark theme. Ideally rich is smart enough to handle most of the situations, but it's also inevitable it will crash with plugins. I can imagine it will interfere with dark-themes browser plugin as well. In that case, we should have an easy way to disable the rich REPL .

image

@astrojuanlu
Copy link
Member

Essentially Textualize/rich#505, Textualize/rich#2484

@astrojuanlu
Copy link
Member

Rich is not doing anything about this issue, and in theory there are themes one can customise but it's not clear to me how to apply them.

Closing this as won't fix. Stay tuned to the linked issues for upcoming changes in how we manage logging and our rich integration.

@astrojuanlu astrojuanlu closed this as not planned Won't fix, can't repro, duplicate, stale Jul 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

No branches or pull requests

5 participants