Get Output From the logging Module in IPython Notebook

前端 未结 9 1594
悲哀的现实
悲哀的现实 2020-11-30 19:19

When I running the following inside IPython Notebook I don\'t see any output:

import logging
logging.basicConfig(level=logging.DEBUG)
logging.debug(\"test\")         


        
9条回答
  •  死守一世寂寞
    2020-11-30 19:57

    Bear in mind that stderr is the default stream for the logging module, so in IPython and Jupyter notebooks you might not see anything unless you configure the stream to stdout:

    import logging
    import sys
    
    logging.basicConfig(format='%(asctime)s | %(levelname)s : %(message)s',
                         level=logging.INFO, stream=sys.stdout)
    
    logging.info('Hello world!')
    

提交回复
热议问题