我在python上编写了一个程序,其中包含日志记录功能。我使用cx_freeze将其转换为.exe。我尝试在Windows上安排.exe。
由于某些原因,当.exe在Windows中安排并以这种方式运行时,日志记录不起作用。它只是记录功能。其他一切都运行良好。当我手动运行.exe时,一切正常。有没有人建议问题是什么?
示例代码我转换为.exe并按计划进行测试:
import time
import logging
logging.basicConfig(filename='test_log.txt', format='%(asctime)s %(message)s', datefmt='%d/%m/%Y %H:%M:%S ')
x = 0
while (x < 20):
#this is here so the loop would run little slower
time.sleep(0.5)
#the event
x = x + 1
# print tha numder
print("number ", x, " is written on console")
#log the event on test_log file
logging.info("number ", x, " is logged")
#log the end of event
logging.info('loop trough')