Skip to content

Commit 647bd25

Browse files
committedDec 16, 2017
[processing] Use a more unique separator for log file
Fixes #17704
1 parent 9d25119 commit 647bd25

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed
 

‎python/plugins/processing/core/ProcessingLog.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
from processing.core.ProcessingConfig import ProcessingConfig
3333
from qgis.PyQt.QtCore import QCoreApplication
3434

35+
LOG_SEPARATOR = '|~|'
36+
3537

3638
class 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))
Code has comments. Press enter to view.
112118

113119
@staticmethod
114120
def tr(string, context=''):

0 commit comments

Comments
 (0)
Please sign in to comment.