diff --git a/python/plugins/processing/core/ProcessingLog.py b/python/plugins/processing/core/ProcessingLog.py index 25b79077213..54de374f56b 100644 --- a/python/plugins/processing/core/ProcessingLog.py +++ b/python/plugins/processing/core/ProcessingLog.py @@ -134,6 +134,14 @@ class ProcessingLog: os.unlink(ProcessingLog.logFilename()) ProcessingLog.startLogging() + @staticmethod + def saveLog(fileName): + entries = ProcessingLog.getLogEntries() + with codecs.open(fileName, 'w', encoding='utf-8') as f: + for k, v in entries.iteritems(): + for entry in v: + f.write('%s|%s|%s\n' % (k, entry.date, entry.text)) + class LogEntry: diff --git a/python/plugins/processing/gui/HistoryDialog.py b/python/plugins/processing/gui/HistoryDialog.py index 0a290d5fc6b..6bcd11690e7 100644 --- a/python/plugins/processing/gui/HistoryDialog.py +++ b/python/plugins/processing/gui/HistoryDialog.py @@ -51,9 +51,14 @@ class HistoryDialog(QDialog, Ui_DlgHistory): self.clearButton.setToolTip(self.tr('Clear history and log')) self.buttonBox.addButton(self.clearButton, QDialogButtonBox.ActionRole) + self.saveButton = QPushButton(self.tr('Save As...')) + self.saveButton.setToolTip(self.tr('Save history and log')) + self.buttonBox.addButton(self.saveButton, QDialogButtonBox.ActionRole) + self.tree.doubleClicked.connect(self.executeAlgorithm) self.tree.currentItemChanged.connect(self.changeText) self.clearButton.clicked.connect(self.clearLog) + self.saveButton.clicked.connect(self.saveLog) self.tree.setContextMenuPolicy(Qt.CustomContextMenu) self.tree.customContextMenuRequested.connect(self.showPopupMenu) @@ -70,6 +75,18 @@ class HistoryDialog(QDialog, Ui_DlgHistory): ProcessingLog.clearLog() self.fillTree() + def saveLog(self): + fileName = QFileDialog.getSaveFileName(self, + self.tr('Save file'), '.', 'Log files (*.log *.LOG)') + + if fileName == '': + return + + if not fileName.lower().endswith('.log'): + fileName += '.log' + + ProcessingLog.saveLog(fileName) + def fillTree(self): self.tree.clear() elements = ProcessingLog.getLogEntries()