Acccess Jupyter Server Logs

Hi

I am using JupyterLab 3 in a Docker on a remote EC2 instance on AWS
I want to be able to see in the docker logs the requests made to the kernel - i.e. a log for each cell submission (hopefully with the code in it)
I am looking for a way to configure this using the jupyter_notebook_config.py file
Has anyone done something similar?

Thanks

I believe the bit you’re looking for is Session.debug and the logging is produced from the jupyter_client package. This can be configured in the notebook config file using c.Session.debug = True or on the command line using --Session.debug=True.

This produces LOTS of logging which can contain potentially sensitive information - so please restrain its use to protected environments.

do i need a certain version for this to work?
I am using:

notebook==6.4.3
jupyter-client==7.0.1
jupyter-contrib-core==0.3.3
jupyter-contrib-nbextensions==0.5.1
jupyter-highlight-selected-word==0.2.0
jupyter-latex-envs==1.4.6
jupyter-nbextensions-configurator==0.4.1
jupyter-resource-usage==0.6.0
jupyter-server==1.10.2
jupyterlab==3.1.9
jupyterlab-server==2.7.2
jupyterlab-system-monitor==0.8.0
jupyterlab-topbar==0.6.1

No, not that I’m aware. Here’s my env:

$ jupyter --version
jupyter core     : 4.7.1
jupyter-notebook : 6.4.3
qtconsole        : not installed
ipython          : 7.27.0
ipykernel        : 6.3.1
jupyter client   : 7.0.2
jupyter lab      : 3.1.1
nbconvert        : 6.1.0
ipywidgets       : not installed
nbformat         : 5.1.3
traitlets        : 5.1.0

and command line:
$ jupyter notebook --Session.debug=True --notebook-dir=~/notebooks/

and log output after starting a kernel:

[I 09:56:49.301 NotebookApp] Kernel started: 3aa544f4-a944-46fd-8bbf-755bdd48baf4, name: python3
{'content': {},
 'header': {'date': datetime.datetime(2021, 9, 1, 16, 56, 49, 382864, tzinfo=datetime.timezone.utc),
            'msg_id': '6cdf85db0a5f49e39b5cba964e7e03fb_8109_0',
            'msg_type': 'kernel_info_request',
            'session': '6cdf85db0a5f49e39b5cba964e7e03fb',
            'username': 'kbates',
            'version': '5.3'},
 'metadata': {},
 'msg_id': '6cdf85db0a5f49e39b5cba964e7e03fb_8109_0',
 'msg_type': 'kernel_info_request',
 'parent_header': {}}
[b'<IDS|MSG>',
 b'3855b129856e387470f2170ae1a0d0e109bc9789c692e4671be26747a6cddd54',
 b'{"msg_id": "6cdf85db0a5f49e39b5cba964e7e03fb_8109_0", "msg_type": "kernel_in'
 b'fo_request", "username": "kbates", "session": "6cdf85db0a5f49e39b5cba964e7e0'
 b'3fb", "date": "2021-09-01T16:56:49.382864Z", "version": "5.3"}',
 b'{}',
 b'{}',
 b'{}']
[]

What output do you see in your terminal from which the server was started?

Ok so after a bit of testing, when I add the command line argument like you described --Session.debug=True I can see the logs like you show here,
But when I add this configuration in the jupyter_notebook_config.py file it does not show :open_mouth:

That’s odd. If I build my config file using jupyter notebook --generate-config, I have a section named Session(Configurable) configuration. I then modify the debug entry, to set the value to True:

## Debug output in the Session
#  Default: False
# c.Session.debug = False
c.Session.debug = True

and receive the desired logging using only jupyter notebook.

If your config file was not built that way, it shouldn’t matter, you just need the c.Session.debug = True entry. Note that the c. prefix matters within the python config file.

Got it to work, was my bad :slight_smile:

Can you tell me if adding this flag is production safe?

Also is there is any way to configure the debug logs? For example, write only data for cell execution and not kernel idle, etc.
The debug is a LOT of data