Skip to content
Permalink
Browse files
QgsProcessingFeedback: limit number of messages to avoid blowing RAM (f…
…ixes #44202)
  • Loading branch information
rouault authored and nyalldawson committed Jul 21, 2021
1 parent 3dae957 commit a52b2bf060e3dc68cef9769b079c536c24c51cdc
Showing with 35 additions and 10 deletions.
  1. +30 −10 src/core/processing/qgsprocessingfeedback.cpp
  2. +5 −0 src/core/processing/qgsprocessingfeedback.h
@@ -36,22 +36,42 @@ void QgsProcessingFeedback::setProgressText( const QString & )
{
}

void QgsProcessingFeedback::log( const QString &htmlMessage, const QString &textMessage )
{
constexpr int MESSAGE_COUNT_LIMIT = 10000;
// Avoid logging too many messages, which might blow memory.
if ( mMessageLoggedCount == MESSAGE_COUNT_LIMIT )
return;
++mMessageLoggedCount;
if ( mMessageLoggedCount == MESSAGE_COUNT_LIMIT )
{
mHtmlLog.append( QStringLiteral( "<span style=\"color:red\">%1</span><br/>" ).arg( tr( "Message log truncated" ) ) );
mTextLog.append( tr( "Message log truncated" ) + '\n' );
}
else
{
mHtmlLog.append( htmlMessage );
mTextLog.append( textMessage );
}
}


void QgsProcessingFeedback::reportError( const QString &error, bool )
{
if ( mLogFeedback )
QgsMessageLog::logMessage( error, tr( "Processing" ), Qgis::MessageLevel::Critical );

mHtmlLog.append( QStringLiteral( "<span style=\"color:red\">%1</span><br/>" ).arg( error.toHtmlEscaped() ).replace( '\n', QLatin1String( "<br>" ) ) );
mTextLog.append( error + '\n' );
log( QStringLiteral( "<span style=\"color:red\">%1</span><br/>" ).arg( error.toHtmlEscaped() ).replace( '\n', QLatin1String( "<br>" ) ),
error + '\n' );
}

void QgsProcessingFeedback::pushWarning( const QString &warning )
{
if ( mLogFeedback )
QgsMessageLog::logMessage( warning, tr( "Processing" ), Qgis::MessageLevel::Warning );

mHtmlLog.append( QStringLiteral( "<span style=\"color:#b85a20;\">%1</span><br/>" ).arg( warning.toHtmlEscaped() ).replace( '\n', QLatin1String( "<br>" ) ) + QStringLiteral( "<br/>" ) );
mTextLog.append( warning + '\n' );
log( QStringLiteral( "<span style=\"color:#b85a20;\">%1</span><br/>" ).arg( warning.toHtmlEscaped() ).replace( '\n', QLatin1String( "<br>" ) ) + QStringLiteral( "<br/>" ),
warning + '\n' );
}

void QgsProcessingFeedback::pushInfo( const QString &info )
@@ -68,26 +88,26 @@ void QgsProcessingFeedback::pushCommandInfo( const QString &info )
if ( mLogFeedback )
QgsMessageLog::logMessage( info, tr( "Processing" ), Qgis::MessageLevel::Info );

mHtmlLog.append( QStringLiteral( "<code>%1</code><br/>" ).arg( info.toHtmlEscaped().replace( '\n', QLatin1String( "<br>" ) ) ) );
mTextLog.append( info + '\n' );
log( QStringLiteral( "<code>%1</code><br/>" ).arg( info.toHtmlEscaped().replace( '\n', QLatin1String( "<br>" ) ) ),
info + '\n' );
}

void QgsProcessingFeedback::pushDebugInfo( const QString &info )
{
if ( mLogFeedback )
QgsMessageLog::logMessage( info, tr( "Processing" ), Qgis::MessageLevel::Info );

mHtmlLog.append( QStringLiteral( "<span style=\"color:#777\">%1</span><br/>" ).arg( info.toHtmlEscaped().replace( '\n', QLatin1String( "<br>" ) ) ) );
mTextLog.append( info + '\n' );
log( QStringLiteral( "<span style=\"color:#777\">%1</span><br/>" ).arg( info.toHtmlEscaped().replace( '\n', QLatin1String( "<br>" ) ) ),
info + '\n' );
}

void QgsProcessingFeedback::pushConsoleInfo( const QString &info )
{
if ( mLogFeedback )
QgsMessageLog::logMessage( info, tr( "Processing" ), Qgis::MessageLevel::Info );

mHtmlLog.append( QStringLiteral( "<code style=\"color:#777\">%1</code><br/>" ).arg( info.toHtmlEscaped().replace( '\n', QLatin1String( "<br>" ) ) ) );
mTextLog.append( info + '\n' );
log( QStringLiteral( "<code style=\"color:#777\">%1</code><br/>" ).arg( info.toHtmlEscaped().replace( '\n', QLatin1String( "<br>" ) ) ),
info + '\n' );
}

void QgsProcessingFeedback::pushVersionInfo( const QgsProcessingProvider *provider )
@@ -140,9 +140,13 @@ class CORE_EXPORT QgsProcessingFeedback : public QgsFeedback
virtual QString textLog() const;

private:

void log( const QString &htmlMessage, const QString &textMessage );

bool mLogFeedback = true;
QString mHtmlLog;
QString mTextLog;
int mMessageLoggedCount = 0;

};

@@ -196,6 +200,7 @@ class CORE_EXPORT QgsProcessingMultiStepFeedback : public QgsProcessingFeedback
int mChildSteps = 0;
int mCurrentStep = 0;
QgsProcessingFeedback *mFeedback = nullptr;

};

#endif // QGSPROCESSINGFEEDBACK_H

0 comments on commit a52b2bf

Please sign in to comment.