import logging # logging.disable(logging.CRITICAL) logging.basicConfig(filename="loggingBug.txt",level=logging.DEBUG,format="%(asctime)s-%(levelname)s-%(message)s") def factorial(num): total=1 logging.debug("开始运行:{}".format(num)) for i in range(1,num+1): logging.debug("i={},total={}".format(i,total)) total*=i return total print(factorial(5))
是为了方便我以后查阅,所以注释不是很详细,如果有问题,可以尽情留言私信,我都会回复~