Jupyter notebook does not print logs to the output cell

后端 未结 4 1609
一个人的身影
一个人的身影 2021-01-17 15:27

I am currently using Jupyter notebook and I would like to force it to print out Python logs to the output cell.

I am using old notebook tha

4条回答
  •  孤独总比滥情好
    2021-01-17 15:51

    The earlier answers seem no longer to work. The most complete one no longer works because there are no default handlers, so modifying the zeroeth doesn't work. Also, messing with the root logger seems potentially fraught when running in a notebook.

    In order to get the "foo" logger to put its output in the cell you can do the following:

    logger = logging.getLogger("foo")
    logger.addHandler(logging.StreamHandler(stream=sys.stdout))
    

    So add the handler yourself, and direct its output.

提交回复
热议问题