Jupyter does not print logging information

I’m using the notebook via JupyterHub, the same script can show logging information (import logging) as well as warnings in the command line, however, in the notebook, only the warning is shown. The logging information is not printed, and not saved in the designated .txt file either.

Note: the notebook once showed the loggings, but not sure why it doesn’t work now.

Thank you!

Does it work if you run JupyterLab directly instead of via JupyterHub?

1 Like

Thanks for your reply. I figured out what I can do. It seems that the logging setting was messed up somewhere in the script when I ran it in Jupyterhub, and the setting could not be overwritten. If I add the following lines to setup logging at the beginning of my script, it will work fine!

import logging
import sys
date_strftime_format = “%Y-%m-%y %H:%M:%S”
logging.basicConfig(stream=sys.stdout, level=logging.INFO, format="%(asctime)s %(message)s", datefmt=date_strftime_format)

1 Like

For a little more detail, I believe logging goes to sys.__stderr__ by default (not sys.stderr!), which means being sent to the terminal where the server is running (not super useful). So as you did, picking the captured sys.stdout means it will get captured and included in notebook output.

1 Like

Thank you! I found out what messed up the logging setting in the script, it’s when I do import jax; print(jax.devices). It seems that jax uses the Abseil logging system which is implemented on top of the standard logging module in Python. I’m not familiar with how to setup the abseil logging or how to stop print(jax.devices) from changing the logging setting, but I found that if I setup the logging config upfront, it’s fine.