Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log from Supy and CDSAPI #157

Open
biglimp opened this issue Apr 22, 2020 · 4 comments
Open

Log from Supy and CDSAPI #157

biglimp opened this issue Apr 22, 2020 · 4 comments
Assignees
Labels
enhancement New feature or request trivial

Comments

@biglimp
Copy link
Contributor

biglimp commented Apr 22, 2020

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

@sunt05
Copy link
Contributor

sunt05 commented Apr 22, 2020

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?

@biglimp
Copy link
Contributor Author

biglimp commented Apr 23, 2020

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 biglimp added the enhancement New feature or request label Oct 29, 2020
@biglimp
Copy link
Contributor Author

biglimp commented Jun 28, 2022

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

@sunt05
Copy link
Contributor

sunt05 commented Jun 28, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request trivial
Projects
None yet
Development

No branches or pull requests

2 participants