I need to have my daily txt file that is written here sent to the path "keypad__logger" which i have created. I cannot seem to correctly us os.path to direct the file properly.
from datetime import datetime
from threading import Timer
import time, threading
import os.path
class Spider_Log():
def log(self, LOG_TAG, LOG_MESSAGE):
print('{}: {}'.format(LOG_TAG, LOG_MESSAGE))
# TODO: append to daily log file
now = datetime.utcnow()
print(now)
year = now.year
day = now.day
month = now.month
print("keypad__logger has been created")
print('year = {}, month = {}, day = {}'.format(year, month, day))
with open('log_{}_{}_{}.txt'.format(year, month, day), 'a+') as f:
f.write('{} \t {}: {} \n'.format(now, LOG_TAG, LOG_MESSAGE))
def thread_to_keep_time(self, event):
with open('log_{}_{}_{}.txt'):
while True:
time.sleep(10)
event.set()
timer_event = threading.Event()
threading.Thread(target=thread_to_keep_time, args=[timer_event]).start()
if __name__ == "__main__":
log = Spider_Log()
tag = 'SPIDERLOG'
log.log(tag, 'test2')
for t in threading.enumerate():
if t != threading.current_thread():
t.join()