Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable and access debug logging for notebook and IPython kernel

I'm doing a small research on IPython kernel and trying to get debug logs out of it and see how it interacts with a notebook. Now it looks like the documentation and example configs shipped in my distribution is totally outdated.

The questions

  1. Where the ipython kernel log files are located?
  2. How can I enable DEBUG level logging in both jupyter notebook and ipython kernel?

What I've tried

Please read this section before giving links to the official docs

First I created profiles for both IPython and notebook with the following commands:

$ ipython profile create
$ jupyter notebook --generate-config

As expected three files where created:

  • .jupyter/jupyter_notebook_config.py
  • .ipython/profile_default/ipython_config.py
  • .ipython/profile_default/ipython_kernel_config.py

In these files I found similar commented fragments:

 # Set the log level by value or name.
 # c.Application.log_level = 0

I tried to uncomment it in the jupyter config. Instead of adding more details it totally disabled console output for the jupyter process. I also tried value 50 it has the same result, value DEBUG gave me Python error on start.

I also played with these values in ipython's configs but I wasn't able to find log files location.

In mail list command line option --log-level=DEBUG is mentioned and indeed it works for jupyter. But I really want to persist this setting in a profile and have debug info for the kernel too.

Config options NotebookApp.log_level and IPKernelApp.log_level also change nothing.

like image 607
CheatEx Avatar asked Nov 10 '15 14:11

CheatEx


People also ask

How do I enable debugging in Jupyter notebook?

Debug code in Jupyter notebooks Alternatively, you can right-click the cell and select Debug Cell from the context menu. The Jupyter Notebook Debugger tool window opens. Debugging is performed within a single code cell.

How do I debug in IPython notebook?

The easiest way to debug a Jupyter notebook is to use the %debug magic command. Whenever you encounter an error or exception, just open a new notebook cell, type %debug and run the cell. This will open a command line where you can test your code and inspect all variables right up to the line that threw the error.


2 Answers

I believe that this kind of functionality is still on the wishlist:

https://github.com/ipython/ipython/issues/8570

But you could try something like this:

jupyter notebook --debug > log.file 2>&1

or

ipykernel kernel --debug > log.file 2>&1
like image 164
lmtx Avatar answered Sep 30 '22 14:09

lmtx


You can also try to start ipython kernel without attached frontend with option --debug:

ipython kernel --debug

You can get lot of info about interaction between kernel and the forntend by setting c.Session.debug = True in jupyter_notebook_config.py.

like image 25
mikolajb Avatar answered Sep 30 '22 13:09

mikolajb