Ejemplo n.º 1
0
    def emit(self, record):
        """Try to log the message to QGIS if available, otherwise do nothing.

        Args:
            record (): logging record containing whatever info needs to be logged.

        Returns:

        """
        # ToDo:Add the warning/info messages to the form messagebar look at QGIS-master\python\utils.py\showException
        # ??https://gis.stackexchange.com/questions/152730/how-to-add-a-message-bar-to-custom-canvas
        # https://gis.stackexchange.com/questions/135711/why-is-the-display-of-qgsmessagebar-delayed
        # https://gis.stackexchange.com/a/216444
        # Check logging.LogRecord properties for lots of other goodies like line number etc. you can get
        # from the log message.
        try:
            if QgsMessageBar is None:
                return

            if self.lastRec is None or self.lastRec.getMessage(
            ) != record.getMessage():
                QgsMessageLog.logMessage(record.getMessage(), PLUGIN_SHORT,
                                         LOG_MAP[record.levelname]['qgis'])
                self.lastRec = record
            QCoreApplication.processEvents()

        except MemoryError:
            message = 'Due to memory limitations on this machine, PrecisionAg can not handle the full log'
            print(message)
            QgsMessageLog.logMessage(message, PLUGIN_SHORT, 0)
        except IOError:
            pass
        except AttributeError:
            pass
Ejemplo n.º 2
0
def openLogPanel():
    logMessagesPanel = iface.mainWindow().findChild(QDockWidget, 'MessageLog')

    # Check to see if it is already open
    if not logMessagesPanel.isVisible():
        logMessagesPanel.setVisible(True)

    # find and set the active tab
    tabWidget = logMessagesPanel.findChildren(QTabWidget)[0]
    for iTab in range(0, tabWidget.count()):
        if tabWidget.tabText(iTab) == PLUGIN_SHORT:
            tabWidget.setCurrentIndex(iTab)
            break

    QCoreApplication.processEvents()