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

2 Answers 2

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.

2
  • 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'" Commented Jan 30, 2021 at 21:56
  • have you tried the following feedback.pushInfo('This is a log message') ?
    – onietosi
    Commented Feb 1, 2021 at 9: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

3
  • that's exactly what I am looking for ! thanks a lot Commented Oct 30, 2017 at 8:53
  • Unfortunately I will get an error: "NameError: name 'progress' is not defined" Do I have to import a special module?
    – Vaiaro
    Commented Oct 16, 2019 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
    Commented Oct 17, 2019 at 18:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.