0

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()   
  • What is the problem? `os.path` is not used in your code. – wwii Aug 19 '20 at 02:04
  • Correct, I have not written it in because i kept getting stuck with it not working properly. I need the "log{}_{}_{}.txt' file to go to the path "keypad__logger" and I cannot figure out how. sorry for not clarifying –  Aug 19 '20 at 14:08
  • `os.path.join( "keypad__logger","log{}_{}_{}.txt')`? - [https://docs.python.org/3/library/os.path.html#os.path.join](https://docs.python.org/3/library/os.path.html#os.path.join) – wwii Aug 19 '20 at 14:52
  • Thank you so much. very helpful! –  Aug 19 '20 at 17:21
  • If this answers your question please vote to close your question as a duplicate. [Build the full path filename in Python](https://stackoverflow.com/questions/7132861/build-the-full-path-filename-in-python) – wwii Aug 23 '20 at 15:05

0 Answers0