Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
QgsProcessingFeedback: limit number of messages to avoid blowing RAM (f…
…ixes #44202)
  • Loading branch information
rouault authored and nyalldawson committed Jul 22, 2021
1 parent f0d696d commit 39d08be
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 10 deletions.
40 changes: 30 additions & 10 deletions src/core/processing/qgsprocessingfeedback.cpp
Expand Up @@ -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::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::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 )
Expand All @@ -68,26 +88,26 @@ void QgsProcessingFeedback::pushCommandInfo( const QString &info )
if ( mLogFeedback )
QgsMessageLog::logMessage( info, tr( "Processing" ), Qgis::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::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::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 )
Expand Down
5 changes: 5 additions & 0 deletions src/core/processing/qgsprocessingfeedback.h
Expand Up @@ -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;

};

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

};

#endif // QGSPROCESSINGFEEDBACK_H
Expand Down

0 comments on commit 39d08be

Please sign in to comment.