Debug/trace logging in a custom Jupyter kernel
Updated:I was unable to get Jupyter to report any logs from my custom kernel, even when I was running jupyter labs --debug.
This was the case for both print calls and logging.{critical,debug,etc.} calls.
To work around it I configured my kernel’s logger to write to a file using logging.basicConfig(filename="kernel.log"). The Jupyter runtime can’t eat these logs up because they aren’t going through stdout. Then I could use calls like logging.debug(some_interesting_variable) to see whatever I wanted.
Side note, when debugging Python in VS-Code, don’t forget to add "justMyCode": false to the debugging config so that you can see third-party libraries.
To debug a Jupyter kernel, use debugpy to allow VS-Code to remotely attach to the process.