8

I want to write some log in the log tab of processing algorithm User Interface.

I tried this :

from qgis.core import QgsMessageLog

QgsMessageLog.logMessage("test")

but when I launch the script "test" is not logged.

enter image description here

How to write a log in the processing User Interface ?

the processing guide log's chapter doesn't tell much about writing a log in this tab.

If i use :

from qgis.core import QgsMessageLog
QgsMessageLog.logMessage("test", tag="Processing", level=QgsMessageLog.INFO)

the log result is wrote under the console log panel called "Processing", but not in the processing GUI log tab. enter image description here

ahmadhanb
  • 40,826
  • 5
  • 51
  • 105
Hugo Roussaffa
  • 2,191
  • 15
  • 40

2 Answers2

9

For QGIS 3.x you can use the pushInfo() method on a feedback object:

feedback.pushInfo('This is a log message')

See the scripts section of the user's manual for other relevant methods.

onietosi
  • 559
  • 6
  • 7
  • how do you create or acquire the feedback object in the first place? with QgsProcessingFeedback.pushInfo('a message') I get the error "TypeError: QgsProcessingFeedback.pushInfo(): first argument of unbound method must have type 'QgsProcessingFeedback'" – matt wilkie Jan 30 '21 at 21:56
  • have you tried the following feedback.pushInfo('This is a log message') ? – onietosi Feb 01 '21 at 09:01
3

You can do this with global variable progress. see the user manual, processing chapter

progress.setText('Youpi')

Will print 'Youpi' in the processing log.

It supports html formatting:

progress.setText('<b>Youpi</b>')

to print in bold...

progress come also with setPercentage() methods to control the progress bar

Hugo Roussaffa
  • 2,191
  • 15
  • 40
YoLecomte
  • 2,895
  • 10
  • 23
  • that's exactly what I am looking for ! thanks a lot – Hugo Roussaffa Oct 30 '17 at 08:53
  • Unfortunately I will get an error: "NameError: name 'progress' is not defined" Do I have to import a special module? – Vaiaro Oct 16 '19 at 16:00
  • 1
    @Vaiaro I wrote this answer long time ago and the api of processing has change a lot... You probably need to check the doc for qgis3 to see the new way of doing that. – YoLecomte Oct 17 '19 at 18:32