Skip to content
Permalink
Browse files
Merge pull request #4400 from nyalldawson/processing_log
[processing] Move some log handling to c++ class
  • Loading branch information
nyalldawson committed Apr 26, 2017
2 parents 6b4ddb3 + e9f13d1 commit 7c9b00c331f985f914de9a8a3f17a51c35fd37c2
Showing with 324 additions and 310 deletions.
  1. +1 −0 doc/api_break.dox
  2. +5 −4 python/plugins/processing/algs/gdal/GdalUtils.py
  3. +5 −6 python/plugins/processing/algs/grass7/Grass7Algorithm.py
  4. +6 −8 python/plugins/processing/algs/grass7/Grass7AlgorithmProvider.py
  5. +5 −3 python/plugins/processing/algs/grass7/Grass7Utils.py
  6. +4 −4 python/plugins/processing/algs/qgis/Centroids.py
  7. +9 −6 python/plugins/processing/algs/qgis/Clip.py
  8. +7 −4 python/plugins/processing/algs/qgis/Difference.py
  9. +14 −14 python/plugins/processing/algs/qgis/Dissolve.py
  10. +7 −4 python/plugins/processing/algs/qgis/EliminateSelection.py
  11. +2 −3 python/plugins/processing/algs/qgis/FixGeometry.py
  12. +5 −9 python/plugins/processing/algs/qgis/Gridify.py
  13. +4 −4 python/plugins/processing/algs/qgis/Heatmap.py
  14. +10 −8 python/plugins/processing/algs/qgis/Intersection.py
  15. +5 −5 python/plugins/processing/algs/qgis/RandomPointsAlongLines.py
  16. +5 −5 python/plugins/processing/algs/qgis/RandomPointsExtent.py
  17. +5 −5 python/plugins/processing/algs/qgis/RandomPointsLayer.py
  18. +3 −4 python/plugins/processing/algs/qgis/RandomPointsPolygonsFixed.py
  19. +3 −4 python/plugins/processing/algs/qgis/RandomPointsPolygonsVariable.py
  20. +25 −25 python/plugins/processing/algs/qgis/RectanglesOvalsDiamondsVariable.py
  21. +11 −3 python/plugins/processing/algs/qgis/ShortestPathLayerToPoint.py
  22. +4 −3 python/plugins/processing/algs/qgis/ShortestPathPointToLayer.py
  23. +5 −4 python/plugins/processing/algs/qgis/SimplifyGeometries.py
  24. +3 −3 python/plugins/processing/algs/qgis/SplitLinesWithLines.py
  25. +2 −3 python/plugins/processing/algs/qgis/SplitWithLines.py
  26. +11 −6 python/plugins/processing/algs/qgis/SymmetricalDifference.py
  27. +22 −18 python/plugins/processing/algs/qgis/Union.py
  28. +4 −4 python/plugins/processing/algs/qgis/ui/FieldsCalculatorDialog.py
  29. +4 −3 python/plugins/processing/algs/r/RAlgorithm.py
  30. +7 −6 python/plugins/processing/algs/r/RAlgorithmProvider.py
  31. +4 −3 python/plugins/processing/algs/r/RUtils.py
  32. +3 −2 python/plugins/processing/algs/saga/SagaAlgorithm.py
  33. +12 −10 python/plugins/processing/algs/saga/SagaAlgorithmProvider.py
  34. +5 −5 python/plugins/processing/algs/saga/SagaUtils.py
  35. +5 −6 python/plugins/processing/core/GeoAlgorithm.py
  36. +6 −12 python/plugins/processing/core/Processing.py
  37. +21 −45 python/plugins/processing/core/ProcessingLog.py
  38. +1 −2 python/plugins/processing/gui/AlgorithmDialog.py
  39. +3 −3 python/plugins/processing/gui/AlgorithmExecutor.py
  40. +3 −3 python/plugins/processing/gui/HelpEditionDialog.py
  41. +9 −11 python/plugins/processing/gui/HistoryDialog.py
  42. +4 −4 python/plugins/processing/gui/Postprocessing.py
  43. +7 −6 python/plugins/processing/modeler/ModelerAlgorithmProvider.py
  44. +8 −6 python/plugins/processing/modeler/ModelerDialog.py
  45. +4 −3 python/plugins/processing/script/ScriptAlgorithm.py
  46. +7 −5 python/plugins/processing/script/ScriptUtils.py
  47. +17 −6 python/plugins/processing/tools/vector.py
  48. +1 −0 src/core/processing/qgsprocessingutils.cpp
  49. +1 −0 src/core/processing/qgsprocessingutils.h
@@ -2229,6 +2229,7 @@ object of type QgsProcessingFeedback, and will need to adapt their use of progre
- SilentProgress was removed. Use the base QgsProcessingFeedback class instead.
- algList was removed. Use QgsApplication.processingRegistry() instead.
- Processing.algs was removed. QgsApplication.processingRegistry().algorithms() instead.
- ProcessingLog should not be used when reporting log messages from algorithms. Use QgsMessageLog.logMessage() instead.

Triangulation {#qgis_api_break_3_0_Triangulation}
-------------
@@ -37,9 +37,10 @@
from qgis.core import (QgsApplication,
QgsVectorFileWriter,
QgsProcessingFeedback,
QgsProcessingUtils,
QgsMessageLog,
QgsSettings)
from processing.core.ProcessingConfig import ProcessingConfig
from processing.core.ProcessingLog import ProcessingLog
from processing.tools.system import isWindows, isMac

try:
@@ -79,7 +80,7 @@ def runGdal(commands, feedback=None):
os.putenv('PATH', envval)

fused_command = ' '.join([str(c) for c in commands])
ProcessingLog.addToLog(ProcessingLog.LOG_INFO, fused_command)
QgsMessageLog.logMessage(fused_command, 'Processing', QgsMessageLog.INFO)
feedback.pushInfo('GDAL command:')
feedback.pushCommandInfo(fused_command)
feedback.pushInfo('GDAL command output:')
@@ -107,8 +108,8 @@ def runGdal(commands, feedback=None):
else:
raise IOError(e.message + u'\nTried 5 times without success. Last iteration stopped after reading {} line(s).\nLast line(s):\n{}'.format(len(loglines), u'\n'.join(loglines[-10:])))

ProcessingLog.addToLog(ProcessingLog.LOG_INFO, loglines)
GdalUtils.consoleOutput = loglines
QgsMessageLog.logMessage('\n'.join(loglines), 'Processing', QgsMessageLog.INFO)
GdalUtils.consoleOutput = loglines

@staticmethod
def getConsoleOutput():
@@ -34,12 +34,13 @@
from qgis.PyQt.QtCore import QCoreApplication, QUrl

from qgis.core import (QgsRasterLayer,
QgsApplication)
QgsApplication,
QgsProcessingUtils,
QgsMessageLog)
from qgis.utils import iface

from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.core.ProcessingConfig import ProcessingConfig
from processing.core.ProcessingLog import ProcessingLog
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException

from processing.core.parameters import (getParameterFromString,
@@ -188,9 +189,7 @@ def defineCharacteristicsFromFile(self):
"txt"))
line = lines.readline().strip('\n').strip()
except Exception as e:
ProcessingLog.addToLog(
ProcessingLog.LOG_ERROR,
self.tr('Could not open GRASS GIS 7 algorithm: {0}\n{1}').format(self.descriptionFile, line))
QgsMessageLog.logMessage(self.tr('Could not open GRASS GIS 7 algorithm: {0}\n{1}').format(self.descriptionFile, line), self.tr('Processing'), QgsMessageLog.CRITICAL)
raise e

self.addParameter(ParameterExtent(
@@ -300,7 +299,7 @@ def processAlgorithm(self, context, feedback):
feedback.pushCommandInfo(line)
loglines.append(line)
if ProcessingConfig.getSetting(Grass7Utils.GRASS_LOG_COMMANDS):
ProcessingLog.addToLog(ProcessingLog.LOG_INFO, loglines)
QgsMessageLog.logMessage(loglines, self.tr('Processing'), QgsMessageLog.INFO)

Grass7Utils.executeGrass7(self.commands, feedback, self.outputCommands)

@@ -29,9 +29,10 @@
import os
from qgis.PyQt.QtCore import QCoreApplication
from qgis.core import (QgsApplication,
QgsProcessingProvider)
QgsProcessingProvider,
QgsMessageLog,
QgsProcessingUtils)
from processing.core.ProcessingConfig import ProcessingConfig, Setting
from processing.core.ProcessingLog import ProcessingLog
from .Grass7Utils import Grass7Utils
from .Grass7Algorithm import Grass7Algorithm
from processing.tools.system import isWindows, isMac
@@ -97,13 +98,10 @@ def createAlgsList(self):
if alg.name().strip() != '':
algs.append(alg)
else:
ProcessingLog.addToLog(
ProcessingLog.LOG_ERROR,
self.tr('Could not open GRASS GIS 7 algorithm: {0}').format(descriptionFile))
QgsMessageLog.logMessage(self.tr('Could not open GRASS GIS 7 algorithm: {0}').format(descriptionFile), self.tr('Processing'), QgsMessageLog.CRITICAL)
except Exception as e:
ProcessingLog.addToLog(
ProcessingLog.LOG_ERROR,
self.tr('Could not open GRASS GIS 7 algorithm: {0}\n{1}').format(descriptionFile, str(e)))
QgsMessageLog.logMessage(
self.tr('Could not open GRASS GIS 7 algorithm: {0}\n{1}').format(descriptionFile, str(e)), self.tr('Processing'), QgsMessageLog.CRITICAL)
algs.append(nviz7())
return algs

@@ -31,10 +31,12 @@
import shutil
import subprocess
import os
from qgis.core import QgsApplication

from qgis.core import (QgsApplication,
QgsProcessingUtils,
QgsMessageLog)
from qgis.PyQt.QtCore import QCoreApplication
from processing.core.ProcessingConfig import ProcessingConfig
from processing.core.ProcessingLog import ProcessingLog
from processing.tools.system import userFolder, isWindows, isMac, tempFolder, mkdir
from processing.tests.TestData import points

@@ -333,7 +335,7 @@ def executeGrass7(commands, feedback, outputCommands=None):
feedback.pushConsoleInfo(line)

if ProcessingConfig.getSetting(Grass7Utils.GRASS_LOG_CONSOLE):
ProcessingLog.addToLog(ProcessingLog.LOG_INFO, loglines)
QgsMessageLog.logMessage('\n'.join(loglines), 'Processing', QgsMessageLog.INFO)

# GRASS session is used to hold the layers already exported or
# produced in GRASS between multiple calls to GRASS algorithms.
@@ -29,10 +29,11 @@

from qgis.PyQt.QtGui import QIcon

from qgis.core import QgsWkbTypes, QgsProcessingUtils
from qgis.core import (QgsWkbTypes,
QgsProcessingUtils,
QgsMessageLog)

from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.core.ProcessingLog import ProcessingLog
from processing.core.parameters import ParameterVector
from processing.core.outputs import OutputVector
from processing.tools import dataobjects, vector
@@ -80,8 +81,7 @@ def processAlgorithm(self, context, feedback):
if input_feature.geometry():
output_geometry = input_feature.geometry().centroid()
if not output_geometry:
ProcessingLog.addToLog(ProcessingLog.LOG_WARNING,
'Error calculating centroid for feature {}'.format(input_feature.id()))
QgsMessageLog.logMessage('Error calculating centroid for feature {}'.format(input_feature.id()), self.tr('Processing'), QgsMessageLog.WARNING)
output_feature.setGeometry(output_geometry)

writer.addFeature(output_feature)
@@ -29,10 +29,14 @@

from qgis.PyQt.QtGui import QIcon

from qgis.core import QgsFeature, QgsGeometry, QgsFeatureRequest, QgsWkbTypes, QgsProcessingUtils
from qgis.core import (QgsFeature,
QgsGeometry,
QgsFeatureRequest,
QgsWkbTypes,
QgsMessageLog,
QgsProcessingUtils)

from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.core.ProcessingLog import ProcessingLog
from processing.core.parameters import ParameterVector
from processing.core.outputs import OutputVector
from processing.tools import dataobjects, vector
@@ -137,10 +141,9 @@ def processAlgorithm(self, context, feedback):
out_feat.setAttributes(in_feat.attributes())
writer.addFeature(out_feat)
except:
ProcessingLog.addToLog(ProcessingLog.LOG_ERROR,
self.tr('Feature geometry error: One or more '
'output features ignored due to '
'invalid geometry.'))
QgsMessageLog.logMessage(self.tr('Feature geometry error: One or more '
'output features ignored due to '
'invalid geometry.'), self.tr('Processing'), QgsMessageLog.CRITICAL)
continue

if single_clip_feature:
@@ -29,8 +29,12 @@

from qgis.PyQt.QtGui import QIcon

from qgis.core import QgsFeatureRequest, QgsFeature, QgsGeometry, QgsWkbTypes, QgsProcessingUtils
from processing.core.ProcessingLog import ProcessingLog
from qgis.core import (QgsFeatureRequest,
QgsFeature,
QgsGeometry,
QgsWkbTypes,
QgsMessageLog,
QgsProcessingUtils)
from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.core.parameters import ParameterVector
from processing.core.outputs import OutputVector
@@ -98,8 +102,7 @@ def processAlgorithm(self, context, feedback):
outFeat.setAttributes(attrs)
writer.addFeature(outFeat)
except:
ProcessingLog.addToLog(ProcessingLog.LOG_WARNING,
self.tr('Feature geometry error: One or more output features ignored due to invalid geometry.'))
QgsMessageLog.logMessage(self.tr('Feature geometry error: One or more output features ignored due to invalid geometry.'), self.tr('Processing'), QgsMessageLog.WARNING)
continue

feedback.setProgress(int(current * total))
@@ -30,9 +30,11 @@

from qgis.PyQt.QtGui import QIcon

from qgis.core import QgsFeature, QgsGeometry, QgsProcessingUtils
from qgis.core import (QgsFeature,
QgsGeometry,
QgsMessageLog,
QgsProcessingUtils)

from processing.core.ProcessingLog import ProcessingLog
from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
from processing.core.parameters import ParameterVector
@@ -106,12 +108,11 @@ def processAlgorithm(self, context, feedback):
errors = tmpInGeom.validateGeometry()
if len(errors) != 0:
for error in errors:
ProcessingLog.addToLog(ProcessingLog.LOG_ERROR,
self.tr('ValidateGeometry()'
'error: One or more '
'input features have '
'invalid geometry: ') +
error.what())
QgsMessageLog.logMessage(self.tr('ValidateGeometry()'
'error: One or more '
'input features have '
'invalid geometry: ') +
error.what(), self.tr('Processing'), QgsMessageLog.CRITICAL)
continue

geom_queue.append(tmpInGeom)
@@ -149,12 +150,11 @@ def processAlgorithm(self, context, feedback):
errors = tmpInGeom.validateGeometry()
if len(errors) != 0:
for error in errors:
ProcessingLog.addToLog(ProcessingLog.LOG_ERROR,
self.tr('ValidateGeometry() '
'error: One or more input'
'features have invalid '
'geometry: ') +
error.what())
QgsMessageLog.logMessage(self.tr('ValidateGeometry() '
'error: One or more input'
'features have invalid '
'geometry: ') +
error.what(), self.tr('Processing'), QgsMessageLog.CRITICAL)

if index_attrs not in attribute_dict:
# keep attributes of first feature
@@ -30,11 +30,14 @@

from qgis.PyQt.QtGui import QIcon

from qgis.core import QgsFeatureRequest, QgsFeature, QgsGeometry
from qgis.core import (QgsFeatureRequest,
QgsFeature,
QgsGeometry,
QgsMessageLog,
QgsProcessingUtils)

from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
from processing.core.ProcessingLog import ProcessingLog
from processing.core.parameters import ParameterVector
from processing.core.parameters import ParameterSelection
from processing.core.outputs import OutputVector
@@ -83,8 +86,8 @@ def processAlgorithm(self, context, feedback):
smallestArea = self.getParameterValue(self.MODE) == self.MODE_SMALLEST_AREA

if inLayer.selectedFeatureCount() == 0:
ProcessingLog.addToLog(ProcessingLog.LOG_WARNING,
self.tr('{0}: (No selection in input layer "{1}")').format(self.displayName(), self.getParameterValue(self.INPUT)))
QgsMessageLog.logMessage(self.tr('{0}: (No selection in input layer "{1}")').format(self.displayName(), self.getParameterValue(self.INPUT)),
self.tr('Processing'), QgsMessageLog.WARNING)

featToEliminate = []
selFeatIds = inLayer.selectedFeatureIds()
@@ -28,13 +28,13 @@
from qgis.core import (QgsWkbTypes,
QgsGeometry,
QgsApplication,
QgsMessageLog,
QgsProcessingUtils)

from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.core.parameters import ParameterVector
from processing.core.outputs import OutputVector
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
from processing.core.ProcessingLog import ProcessingLog
from processing.tools import dataobjects, vector


@@ -88,8 +88,7 @@ def processAlgorithm(self, context, feedback):
if inputFeature.geometry():
outputGeometry = inputFeature.geometry().makeValid()
if not outputGeometry:
ProcessingLog.addToLog(ProcessingLog.LOG_WARNING,
'makeValid failed for feature {}'.format(inputFeature.id()))
QgsMessageLog.logMessage('makeValid failed for feature {}'.format(inputFeature.id()), self.tr('Processing'), QgsMessageLog.WARNING)

if outputGeometry.wkbType() == QgsWkbTypes.Unknown or QgsWkbTypes.flatType(outputGeometry.geometry().wkbType()) == QgsWkbTypes.GeometryCollection:
tmpGeometries = outputGeometry.asGeometryCollection()
@@ -30,10 +30,10 @@
QgsPoint,
QgsWkbTypes,
QgsApplication,
QgsMessageLog,
QgsProcessingUtils)
from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
from processing.core.ProcessingLog import ProcessingLog
from processing.core.parameters import ParameterVector
from processing.core.parameters import ParameterNumber
from processing.core.outputs import OutputVector
@@ -100,8 +100,7 @@ def processAlgorithm(self, context, feedback):
elif geomType == QgsWkbTypes.LineString:
points = self._gridify(geom.asPolyline(), hSpacing, vSpacing)
if len(points) < 2:
ProcessingLog.addToLog(ProcessingLog.LOG_INFO,
self.tr('Failed to gridify feature with FID {0}').format(f.id()))
QgsMessageLog.logMessage(self.tr('Failed to gridify feature with FID {0}').format(f.id()), self.tr('Processing'), QgsMessageLog.INFO)
newGeom = None
else:
newGeom = QgsGeometry.fromPolyline(points)
@@ -112,8 +111,7 @@ def processAlgorithm(self, context, feedback):
if len(points) > 1:
polyline.append(points)
if len(polyline) <= 0:
ProcessingLog.addToLog(ProcessingLog.LOG_INFO,
self.tr('Failed to gridify feature with FID {0}').format(f.id()))
QgsMessageLog.logMessage(self.tr('Failed to gridify feature with FID {0}').format(f.id()), self.tr('Processing'), QgsMessageLog.INFO)
newGeom = None
else:
newGeom = QgsGeometry.fromMultiPolyline(polyline)
@@ -125,8 +123,7 @@ def processAlgorithm(self, context, feedback):
if len(points) > 1:
polygon.append(points)
if len(polygon) <= 0:
ProcessingLog.addToLog(ProcessingLog.LOG_INFO,
self.tr('Failed to gridify feature with FID {0}').format(f.id()))
QgsMessageLog.logMessage(self.tr('Failed to gridify feature with FID {0}').format(f.id()), self.tr('Processing'), QgsMessageLog.INFO)
newGeom = None
else:
newGeom = QgsGeometry.fromPolygon(polygon)
@@ -143,8 +140,7 @@ def processAlgorithm(self, context, feedback):
multipolygon.append(newPolygon)

if len(multipolygon) <= 0:
ProcessingLog.addToLog(ProcessingLog.LOG_INFO,
self.tr('Failed to gridify feature with FID {0}').format(f.id()))
QgsMessageLog.logMessage(self.tr('Failed to gridify feature with FID {0}').format(f.id()), self.tr('Processing'), QgsMessageLog.INFO)
newGeom = None
else:
newGeom = QgsGeometry.fromMultiPolygon(multipolygon)
Loading

0 comments on commit 7c9b00c

Please sign in to comment.