3232from processing .core .ProcessingConfig import ProcessingConfig
3333from qgis .PyQt .QtCore import QCoreApplication
3434
35+ LOG_SEPARATOR = '|~|'
36+
3537
3638class ProcessingLog :
3739
@@ -55,8 +57,8 @@ def addToLog(msg):
5557 # added. To avoid it stopping the normal functioning of the
5658 # algorithm, we catch all errors, assuming that is better
5759 # to miss some log info than breaking the algorithm.
58- line = 'ALGORITHM|' + datetime .datetime .now ().strftime (
59- ProcessingLog .DATE_FORMAT ) + '|' \
60+ line = 'ALGORITHM' + LOG_SEPARATOR + datetime .datetime .now ().strftime (
61+ ProcessingLog .DATE_FORMAT ) + LOG_SEPARATOR \
6062 + msg + '\n '
6163 with codecs .open (ProcessingLog .logFilename (), 'a' ,
6264 encoding = 'utf-8' ) as logfile :
@@ -80,10 +82,14 @@ def getLogEntries():
8082 lines = f .readlines ()
8183 for line in lines :
8284 line = line .strip ('\n ' ).strip ()
83- tokens = line .split ('|' )
85+ tokens = line .split (LOG_SEPARATOR )
86+ if len (tokens ) <= 1 :
87+ # try old format log separator
88+ tokens = line .split ('|' )
89+
8490 text = ''
8591 for i in range (2 , len (tokens )):
86- text += tokens [i ] + '|'
92+ text += tokens [i ] + LOG_SEPARATOR
8793 if line .startswith ('ALGORITHM' ):
8894 entries .append (LogEntry (tokens [1 ], tokens [2 ]))
8995
@@ -108,7 +114,7 @@ def saveLog(fileName):
108114 entries = ProcessingLog .getLogEntries ()
109115 with codecs .open (fileName , 'w' , encoding = 'utf-8' ) as f :
110116 for entry in entries :
111- f .write ('ALGORITHM|%s|%s \n ' % ( entry .date , entry .text ))
117+ f .write ('ALGORITHM{}{}{}{} \n ' . format ( LOG_SEPARATOR , entry .date , LOG_SEPARATORentry .text ))
112118
113119 @staticmethod
114120 def tr (string , context = '' ):
0 commit comments