jeudi 2 avril 2015

Python logging doesn't work when I schedule the task in windows

I wrote a program on python that has logging functions in it. I converted it to an .exe using cx_freeze. I try to schedule the .exe on windows.


For some reason logging doesn't work when the .exe is scheduled in windows and run by that way. It's only the logging function. Everything else runs and works fine. When I run the .exe manually everything works fine. Does anybody have a suggestion what's the problem is?


Example code I converted to an .exe and tested to schedule:



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')

Aucun commentaire:

Enregistrer un commentaire