Friday, 30 September 2016

pyqgis - How to solve issue with log messages panel in QGIS: "Not logging more than 100 request errors."?


I am using the following code in pyqgis to catch errors/warning from a WMS-layer, in order to trigger a repaint as soon as an error/warning is detected (based on previous question: How to catch WMS error message from log messages panel in QGIS with python?)



But obviously the "WMS" provider seems to have a restriction of not sending more than 100 error requests to the messages log, meaning after the 100th error/warning I´m no longer able to catch any signal, even if the WMS-layer is still not responding correctly. Nevertheless, if I send own messages to the log panel there does not seem to be any restriction (see code below).


Is there a possibility to catch the error/warning directly from the instance that is responsible here (I guess it is the WMS-provider), instead of using the messages log panel? Or maybe just clear/reset the log messages panel in a running process or remove the limitation?


I am using QGIS 2.18.2 on Windows 10.


Here is the python code:


# coding=utf-8

from qgis.core import *

wmsLayer_name="wms-dtk50_wgs"
url_with_params ='url=http://sg.geodatenzentrum.de/wms_dtk50?&crs=EPSG:25832&featureCount=10&format=image/png&layers=DTK50&styles='


wmsLayer = QgsRasterLayer(url_with_params, wmsLayer_name,'wms')
QgsMapLayerRegistry.instance().addMapLayer(wmsLayer)

def errorCatcher( msg, tag, level ):
if tag == 'WMS' and level != 0: #Warnings or Errors (0: Info, 1:Warning, 2:Error)
print "WMS error detected!"
myWMSLayer = QgsMapLayerRegistry.instance().mapLayersByName("wms-dtk50_wgs")[0]
myWMSLayer.triggerRepaint()


# connect with messageReceived SIGNAL from QgsMessageLog to an errorCatcher custom function
# instantly reacts if error/warning occurs
QgsMessageLog.instance().messageReceived.connect( errorCatcher )

#after 100 times triggering a "wmsLayer.triggerRepaint()",
# I get following warning in log messages panel "WMS":
# "2017-01-17T07:17:52 1 Not logging more than 100 request errors."

#this does not raise any issues and prints all 500 test messages in the log panel:
for i in range(500):

QgsMessageLog.instance().logMessage("Message #{}".format(i),"Test",2)

enter image description here


UPDATE: I submitted a feature request (see: https://hub.qgis.org/issues/16168)



Answer



Right now, the 100 limit is hard coded in the WMS provider. But QGIS is a wonderful open source project and you can submit a feature request to turn this limit into a configurable parameter.


Any developer can take this feature request and submit a new pull request to QGIS. If the solution is accepted, core developers will be happy to apply the changes both for the upcoming version 3 and for the current 2.14.x and 2.18.x versions.


So, the answer your question is a new feature request submission to QGIS.


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...