Skip to content
Permalink
Browse files

[processing] Only show detailed logging messages when running a model

algorithm IF the model is being run through the model designer dialog

If you run it from the toolbox (or as a sub-component in another model)
then skip all the additional verbose debugging information that normally
gets logged.

This avoids a whole lot of unnecessary log noise when running models,
unless you're actively working on changing the model.
  • Loading branch information
nyalldawson committed Apr 28, 2020
1 parent 69e841a commit 64caa4c03d168bfb7b68b3e40a373d24d99ff329
@@ -42,6 +42,9 @@ QgsProcessingModelAlgorithm::QgsProcessingModelAlgorithm( const QString &name, c

void QgsProcessingModelAlgorithm::initAlgorithm( const QVariantMap & )
{
std::unique_ptr< QgsProcessingParameterBoolean > verboseLog = qgis::make_unique< QgsProcessingParameterBoolean >( QStringLiteral( "VERBOSE_LOG" ), QObject::tr( "Verbose logging" ), false, true );
verboseLog->setFlags( verboseLog->flags() | QgsProcessingParameterDefinition::FlagHidden );
addParameter( verboseLog.release() );
}

QString QgsProcessingModelAlgorithm::name() const
@@ -276,6 +279,8 @@ QVariantMap QgsProcessingModelAlgorithm::processAlgorithm( const QVariantMap &pa
QVariantMap childResults;
QVariantMap childInputs;

const bool verboseLog = parameterAsBool( parameters, QStringLiteral( "VERBOSE_LOG" ), context );

QVariantMap finalResults;
QSet< QString > executed;
bool executedAlg = true;
@@ -309,7 +314,7 @@ QVariantMap QgsProcessingModelAlgorithm::processAlgorithm( const QVariantMap &pa
const QgsProcessingModelChildAlgorithm &child = mChildAlgorithms[ childId ];
std::unique_ptr< QgsProcessingAlgorithm > childAlg( child.algorithm()->create( child.configuration() ) );

const bool skipGenericLogging = childAlg->flags() & QgsProcessingAlgorithm::FlagSkipGenericModelLogging;
const bool skipGenericLogging = !verboseLog || childAlg->flags() & QgsProcessingAlgorithm::FlagSkipGenericModelLogging;
if ( feedback && !skipGenericLogging )
feedback->pushDebugInfo( QObject::tr( "Prepare algorithm: %1" ).arg( childId ) );

@@ -1904,5 +1909,13 @@ void QgsProcessingModelAlgorithm::setVariables( const QVariantMap &variables )
mVariables = variables;
}

QVariantMap QgsProcessingModelAlgorithm::designerParameterValues() const
{
QVariantMap res = mDesignerParameterValues;
// when running through the designer, we show a detailed verbose log to aid in model debugging
res.insert( QStringLiteral( "VERBOSE_LOG" ), true );
return res;
}

///@endcond

@@ -489,7 +489,7 @@ class CORE_EXPORT QgsProcessingModelAlgorithm : public QgsProcessingAlgorithm
*
* \since QGIS 3.14
*/
QVariantMap designerParameterValues() const { return mDesignerParameterValues; }
QVariantMap designerParameterValues() const;

/**
* Sets the parameter \a values to use as default values when running this model through the
@@ -8596,6 +8596,9 @@ void TestQgsProcessing::modelerAlgorithm()
lastParams.insert( QStringLiteral( "a" ), 2 );
lastParams.insert( QStringLiteral( "b" ), 4 );
alg.setDesignerParameterValues( lastParams );

// we expect the result to add in some custom parameters -- namely the verbose log switch
lastParams.insert( QStringLiteral( "VERBOSE_LOG" ), true );
QCOMPARE( alg.designerParameterValues(), lastParams );

// child algorithms
@@ -355,6 +355,7 @@ void TestProcessingGui::testModelUndo()
// the last used parameter values setting should not be affected by undo stack changes
QVariantMap params;
params.insert( QStringLiteral( "a" ), 1 );
params.insert( QStringLiteral( "VERBOSE_LOG" ), true );
model.setDesignerParameterValues( params );
command.undo();
QCOMPARE( model.designerParameterValues(), params );

0 comments on commit 64caa4c

Please sign in to comment.
You can’t perform that action at this time.