hass-pyscript-jupyter icon indicating copy to clipboard operation
hass-pyscript-jupyter copied to clipboard

Only log.error gets prints in jupyter notebook tutorial. log.debug produces no output.

Open evelant opened this issue 3 years ago • 4 comments

Trying out pyscript with the jupyter notebook tutorial and none of the log.debug messages print anything. I'm connected successfully and can read states but only log.errors prints results in the notebook and log.warn is not defined. I've never used jupyter before and have little python experience so I'm sorry if I've missed something obvious.

evelant avatar Nov 24 '21 15:11 evelant

I'm in the same boat: little Python experience, no Jupyter experience. I noticed that my print statements are going to the core log for HA, or at least attempting to, which makes sense. But, it would be nice if there was an explanation in the README on how to redirect output to somewhere easily readable.

r-j-taylor avatar Nov 28 '21 23:11 r-j-taylor

I had a similar issue where log statements weren't printing, and I figured out it was due to the log level that the logging module sees. I think when loading the jupyter kernel, it's supposed to set the level to logging.DEBUG, but I think the following errors were due to it failing.

hass_pyscript_kernel: iopub_port c2k: read EOF; shutdown with exit_status=0 hass_pyscript_kernel: shell_port c2k: read EOF; shutdown with exit_status=0 hass_pyscript_kernel: control_port c2k: read EOF; shutdown with exit_status=0 hass_pyscript_kernel: stdin_port c2k: read EOF; shutdown with exit_status=0

Either way, I was able to get the logger myself and set the level and format string.

import logging
log_level = logging.DEBUG
logging.basicConfig(level=log_level, format="%(message)s")
logging.getLogger().setLevel(log_level)

In case there are any other effects, you can set a higher logging level, like logging.INFO or just print with log.info() or log.warning() (note that log.warn is a typo)

I didn't do any further debugging, but if it helps I'm running python 3.10.0 on MacOS, and running Home Assistant OS

zrsmithson avatar Dec 09 '21 19:12 zrsmithson

I'm facing the same issue. @zrsmithson suggestion also worked here.

gosoares avatar Mar 31 '22 23:03 gosoares

I also see this same issue, although you have to enable arbitrary imports to import logging to change this in the first place

CorvetteCole avatar Mar 05 '23 18:03 CorvetteCole