我收到此记录器错误,我不确定这是怎么发生的.我创建了更简单的测试程序,他们工作.有任何关于这个错误可能来自何方的想法?
在python 2.6中运行这个程序!
错误:
No handlers could be found for logger "__main__"
码:
import logging import subprocess as sp logger = logging.getLogger(__name__) def runpig(filename): # does not use logger .... .... return def main(): try: runpig(filename) except sp.CalledProcessError as ex: logger.error(ex.message) except: logger.info("Error occured") if __name__ == "__main__": main()
解决方法
您需要先调用
logging.basicConfig
,或者只调用logging.info,它会自动调用它.
if __name__ == "__main__": logging.info("Begin") main()
这应该工作