logging not writing to file when called from function in Pyscripter

白昼怎懂夜的黑 提交于 2019-12-02 06:03:01

问题


Currently if I run the following code from the python command line it writes to the file specified by filename as expected.

import logging
def test():
    logging.basicConfig(format='%(asctime)s %(message)s',
                        datefmt='%m/%d/%Y %I:%M:%S %p',
                        filename=r'C:\Users\theo\Documents\myLog.txt')
    logging.warning('Example logged message.')
test()

But when I copy the code into one of my functions and run the function with Pyscripter, it does not seem to write the file. How can I get logging to appear in Pyscripter?


回答1:


Pyscripter has an 'External Run' option ( Run > External Run (Alt + F9)), choosing this made the logging work.




回答2:


Switch the Python Engine to Internal. Go to run-->Pyhton Engine-->Internal



来源:https://stackoverflow.com/questions/17223964/logging-not-writing-to-file-when-called-from-function-in-pyscripter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!