Skip to content

Surface the Pyodide logs to the UI #177

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

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

jtpio
Copy link
Member

@jtpio jtpio commented Mar 24, 2025

For jupyterlite/jupyterlite#1498.

Depends on jupyterlite/jupyterlite#1642.

  • Report cricital logs if an exception is caught during the kernel initialization process
  • Expose a new (optional) logger function to report kernel logs
jupyterlite-kernel-status-indicator.mp4
jupyterlite-kernel-critical.mp4

Copy link
Contributor

lite-badge 👈 Try it on ReadTheDocs

};

// Workaround for being able to get information about packages being loaded by Pyodide
// See discussion in https://github.com/pyodide/pyodide/discussions/5512
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @agriyakhetarpal

Wondering if there is a better way to do this? The idea would to get everything that usually gets logged by Pyodide in the dev tools console, at startup but also when loading new packages dynamically.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You probably want to do this and also to set custom standard steam handles. But I assume you're already setting the stream handlers somewhere.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So there are two parts here. One is logging during package loading and one is logging messages sent to Pyodide's but not Python's stdout/stderr. The latter you can override using _pyodide.setStdout and _pyodide.setStderr. The former is a bit trickier. Overriding loadPackage works but only if it hasn't already been imported using from pyodide_js import loadPackage anywhere yet. Also, overriding it to always provide the custom callbacks means that users can no longer override it themselves. I still think that in the long term adding something like pyodide/pyodide#5442 to Pyodide to override the default stream for package logging would be better

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this override does respect it if the user manually calls loadPyodide with their own callbacks.

Copy link

@hoodmane hoodmane May 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ryanking13 maybe we should consider merging some version of pyodide/pyodide#5442 as a stop-gap solution until a more general thing exists. Is anyone planning to work on this soon?

@jtpio jtpio added the enhancement New feature or request label Mar 24, 2025
@jtpio jtpio added this to the 0.6.0 milestone Mar 24, 2025
@juntyr
Copy link
Contributor

juntyr commented Apr 5, 2025

I'm excited to use this feature!

@jtpio jtpio force-pushed the log-kernel-messages branch from f3f8721 to 21a11ce Compare May 5, 2025 16:09
}

const logger = loggerRegistry.getLogger(notebook.sessionContext.path);
logger.log(payload);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These logs are reported as info, which will not make the log console status bar item flash by default since it defaults to warning.

Some users have reported the flash to be irritating: jupyterlab/jupyterlab#11225. So we can let users choose their log level and not default to info.

@agriyakhetarpal
Copy link
Member

agriyakhetarpal commented May 6, 2025

Ah, sorry, @jtpio, I didn't see that I was pinged here!

I remember that @juntyr's https://github.comclimet-eu/pyodide was doing this sort of thing by calling a bunch of pyodide.code.run_js to write to the output streams, and while it was a hack, it seemed to work well.

Edit: oh, I just went through the linked issue, and I see that Juniper has already linked it in their response in jupyterlite/jupyterlite#1498 (comment) 😄

I think the origLoadPackage approach should be fine for now, as I don't think we have a JS API that writes to Pyodide's stdout/stderr.

That said, I'm not an expert on the JS side for Pyodide, so perhaps Hood and Gyeongjae would know :) cc: @hoodmane @ryanking13

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants