# prepared the time of read to save it in log file now = datetime.datetime.now() timestamp = now.strftime("%Y%m%d%H%M%S")

# create the log file if not existing and write message into it if not os.path.isfile(filepath): file = open(filepath, "w") # open a new log file file.write(timestamp + " - " + message) # write the message into file file.close() # close the file os.chmod(filepath, 0o777) # give extra R/W right to the new log file