diff --git a/.gitignore b/.gitignore index 2a1630fe..9185a69a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ *.pyc *.ini -*ENV \ No newline at end of file +*ENV +log.txt \ No newline at end of file diff --git a/DataStructures/logger.py b/DataStructures/logger.py index fc5a44ef..1474e046 100644 --- a/DataStructures/logger.py +++ b/DataStructures/logger.py @@ -6,6 +6,7 @@ ''' from DataStructures.makesmithInitFuncs import MakesmithInitFuncs +import threading class Logger(MakesmithInitFuncs): @@ -13,14 +14,38 @@ class Logger(MakesmithInitFuncs): errorValues = [] recordingPositionalErrors = False + messageBuffer = "" + + #clear the old log file + with open("log.txt", "a") as logFile: + logFile.truncate() + def writeToLog(self, message): ''' - Writes an error message into the log. + Writes a message into the log + + Actual writing is done in a separate thread to no lock up the UI because file IO is + way slow ''' - pass + + self.messageBuffer = self.messageBuffer + message + + if len(self.messageBuffer) > 500: + t = threading.Thread(target=self.writeToFile, args=(self.messageBuffer)) + self.messageBuffer = "" + def writeToFile(self, toWrite): + ''' + + Write to the log file + + ''' + with open("log.txt", "a") as logFile: + logFile.write(toWrite) + + def writeErrorValueToLog(self, error): '''