UMEP icon indicating copy to clipboard operation
UMEP copied to clipboard

Log from Supy and CDSAPI

Open biglimp opened this issue 5 years ago • 4 comments

Ting, I have ported the ERA5 downloader to the Processing Toolbox. It works but it would have been nice to add the log output from CDSAPI and maybe also SuPy to the Log window in the toolbox. Do you have any idea how to get output from the python console (in QGIS) to another log? The QgsProcessing class comes with a feedback capabiliy that can be used to put out text to the log window. See e.g. line 150 in copernicusera5_algorithm.py

biglimp avatar Apr 22 '20 13:04 biglimp

Hi Fredrik, CDSAPI and supy both use the logging module for porting messages to log files/consoles. I think we just need to redirect the outlet from the logging-related functions to the QGIS ones.

Do you have an example for the feedback stuff?

sunt05 avatar Apr 22 '20 15:04 sunt05

e.g.: feedback.setProgressText("Some string output")

The feedback is inherited from the class below (I think) https://qgis.org/pyqgis/3.4/core/QgsProcessingFeedback.html?highlight=feedback#module-QgsProcessingFeedback

If you just have a look at line 150 in copernicusera5_algorithm.py...

biglimp avatar Apr 23 '20 08:04 biglimp

Maybe we can use something like this (found this in another QGIS plugin). There is function called feedback.pushConsoleInfo():

loglines = []
 with subprocess.Popen(fused_command,
                        shell=True,
                        stdout=subprocess.PIPE,
                        stdin=subprocess.DEVNULL,
                        stderr=subprocess.STDOUT,
                        universal_newlines=True) as proc:
      try:
          for line in iter(proc.stdout.readline, ''):
              feedback.pushConsoleInfo(line)
              loglines.append(line)
      except:
          pass

biglimp avatar Jun 28 '22 12:06 biglimp

This looks nice - in fact, supy does produce a SuPy.log file, which seems a good fit to this approach.

sunt05 avatar Jun 28 '22 21:06 sunt05