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.
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
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.
-
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– matt wilkie2021年01月30日 21:56:51 +00:00Commented Jan 30, 2021 at 21:56 -
have you tried the following
feedback.pushInfo('This is a log message')
?onietosi– onietosi2021年02月01日 09:01:51 +00:00Commented Feb 1, 2021 at 9:01
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
-
that's exactly what I am looking for ! thanks a lotHugo Roussaffa– Hugo Roussaffa2017年10月30日 08:53:51 +00:00Commented 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– Vaiaro2019年10月16日 16:00:01 +00:00Commented 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– YoLecomte2019年10月17日 18:32:40 +00:00Commented Oct 17, 2019 at 18:32