Skip to content
Permalink
Browse files

[processing] Use a more unique separator for log file

Fixes #17704
  • Loading branch information
nyalldawson committed Dec 16, 2017
1 parent 9d25119 commit 647bd256b17c7aa6db907a199125fad9dea0404f
Showing with 11 additions and 5 deletions.
  1. +11 −5 python/plugins/processing/core/ProcessingLog.py
@@ -32,6 +32,8 @@
from processing.core.ProcessingConfig import ProcessingConfig
from qgis.PyQt.QtCore import QCoreApplication

LOG_SEPARATOR = '|~|'


class ProcessingLog:

@@ -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:
@@ -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]))

@@ -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=''):

0 comments on commit 647bd25

Please sign in to comment.
You can’t perform that action at this time.