# Empty lists are created to store information to be logged. These lists are always appended with new information
error_messages = []
output_messages = []
# Timestamps are created (import time in necessary)
current_time = time.localtime() # Checking the local date and time of the computer
now1 = time.strftime('%Y%m%d %H:%M:%S', current_time) # Making a timestamp variable
tstamp = time.strftime('%Y%m%d_%H%M%S', current_time)
output_messages.append(now1 + " Fermentation reporting script has started")
output_messages.append(now1 + " Last 30 fermentations: %s" % ", ".join(FileKeys))
error_messages.append(" ERROR: The filtering couldn't be performed")
# A text file is opened and the messages are filled in and saved
with open(r"u:\Python\Fermentation reports\Logfile_" + tstamp + ".txt", "w") as text_file:
text_file.write("\n".join(output_messages))
text_file.write("\n")
text_file.write("\n".join(error_messages))