Skip to content

Commit

Permalink
[processing] Use a more unique separator for log file
Browse files Browse the repository at this point in the history
Fixes #17704
  • Loading branch information
nyalldawson committed Dec 16, 2017
1 parent 9d25119 commit 647bd25
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions python/plugins/processing/core/ProcessingLog.py
Expand Up @@ -32,6 +32,8 @@
from processing.core.ProcessingConfig import ProcessingConfig
from qgis.PyQt.QtCore import QCoreApplication

LOG_SEPARATOR = '|~|'


class ProcessingLog:

Expand All @@ -55,8 +57,8 @@ def addToLog(msg):
# added. To avoid it stopping the normal functioning of the
# algorithm, we catch all errors, assuming that is better
# to miss some log info than breaking the algorithm.
line = 'ALGORITHM|' + datetime.datetime.now().strftime(
ProcessingLog.DATE_FORMAT) + '|' \
line = 'ALGORITHM' + LOG_SEPARATOR + datetime.datetime.now().strftime(
ProcessingLog.DATE_FORMAT) + LOG_SEPARATOR \
+ msg + '\n'
with codecs.open(ProcessingLog.logFilename(), 'a',
encoding='utf-8') as logfile:
Expand All @@ -80,10 +82,14 @@ def getLogEntries():
lines = f.readlines()
for line in lines:
line = line.strip('\n').strip()
tokens = line.split('|')
tokens = line.split(LOG_SEPARATOR)
if len(tokens) <= 1:
# try old format log separator
tokens = line.split('|')

text = ''
for i in range(2, len(tokens)):
text += tokens[i] + '|'
text += tokens[i] + LOG_SEPARATOR
if line.startswith('ALGORITHM'):
entries.append(LogEntry(tokens[1], tokens[2]))

Expand All @@ -108,7 +114,7 @@ def saveLog(fileName):
entries = ProcessingLog.getLogEntries()
with codecs.open(fileName, 'w', encoding='utf-8') as f:
for entry in entries:
f.write('ALGORITHM|%s|%s\n' % (entry.date, entry.text))
f.write('ALGORITHM{}{}{}{}\n'.format(LOG_SEPARATOR, entry.date, LOG_SEPARATORentry.text))

This comment has been minimized.

Copy link
@nirvn

nirvn Dec 16, 2017

Contributor

@nyalldawson , there's a comma missing after the second separator.


@staticmethod
def tr(string, context=''):
Expand Down

0 comments on commit 647bd25

Please sign in to comment.