9

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
41.8k5 gold badges55 silver badges110 bronze badges
asked Oct 28, 2017 at 10:01

2 Answers 2

11

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.

answered Jul 10, 2020 at 16:42
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') ? 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

answered Oct 28, 2017 at 16:25
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? 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. Commented Oct 17, 2019 at 18:32

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.