以下代码确实在“ipython qtconsole”中打印“我希望它打印”,但它不会在普通 IPython 中打印。
import logging
import logging.handlers
log = logging.getLogger()
f = logging.Formatter("%(asctime)s - %(module)s. %(funcName)s - %(levelname)s - %(message)s")
fh = logging.handlers.TimedRotatingFileHandler('log.txt', 'W6')
fh.setFormatter(f)
log.addHandler(fh)
log.setLevel(logging.INFO)
log.info('I want this to print')
但是,在“IPython qtconsole”中,我遇到了不同的问题,我试图在这里解释(效果不太好,无需阅读!)。
你能告诉我为什么吗?
编辑:我使用 Python 2.7
EDIT2:也许我真的只需要添加logging.StreamHandler。