Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[processing][FEATURE] Add "Save Log to File" algorithm for models
This algorithm saves the contents of the execution log (right up to the point in the model at which the 'save log' algorithm executes) to a file. It can be used to automatically store the debugging log when running models for later reference and transparency.
- Loading branch information
1 parent
0684d41
commit 60af337
Showing
11 changed files
with
224 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/*************************************************************************** | ||
qgsalgorithmsavelog.cpp | ||
--------------------- | ||
begin : March 2020 | ||
copyright : (C) 2020 by Nyall Dawson | ||
email : nyall dot dawson at gmail dot com | ||
***************************************************************************/ | ||
|
||
/*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#include "qgsalgorithmsavelog.h" | ||
|
||
///@cond PRIVATE | ||
|
||
QString QgsSaveLogToFileAlgorithm::name() const | ||
{ | ||
return QStringLiteral( "savelog" ); | ||
} | ||
|
||
QgsProcessingAlgorithm::Flags QgsSaveLogToFileAlgorithm::flags() const | ||
{ | ||
return QgsProcessingAlgorithm::flags() | FlagHideFromToolbox | FlagSkipGenericModelLogging; | ||
} | ||
|
||
QString QgsSaveLogToFileAlgorithm::displayName() const | ||
{ | ||
return QObject::tr( "Save log to file" ); | ||
} | ||
|
||
QStringList QgsSaveLogToFileAlgorithm::tags() const | ||
{ | ||
return QObject::tr( "record,messages,logged" ).split( ',' ); | ||
} | ||
|
||
QString QgsSaveLogToFileAlgorithm::group() const | ||
{ | ||
return QObject::tr( "Modeler tools" ); | ||
} | ||
|
||
QString QgsSaveLogToFileAlgorithm::groupId() const | ||
{ | ||
return QStringLiteral( "modelertools" ); | ||
} | ||
|
||
QString QgsSaveLogToFileAlgorithm::shortHelpString() const | ||
{ | ||
return QObject::tr( "This algorithm saves the model's execution log to a file.\n" | ||
"Optionally, the log can be saved in a HTML formatted version." ); | ||
} | ||
|
||
QString QgsSaveLogToFileAlgorithm::shortDescription() const | ||
{ | ||
return QObject::tr( "Saves the model's log contents to a file." ); | ||
} | ||
|
||
QgsSaveLogToFileAlgorithm *QgsSaveLogToFileAlgorithm::createInstance() const | ||
{ | ||
return new QgsSaveLogToFileAlgorithm(); | ||
} | ||
|
||
void QgsSaveLogToFileAlgorithm::initAlgorithm( const QVariantMap & ) | ||
{ | ||
addParameter( new QgsProcessingParameterFileDestination( QStringLiteral( "OUTPUT" ), QObject::tr( "Log file" ), QObject::tr( "Text files (*.txt);;HTML files (*.html *.HTML)" ) ) ); | ||
addParameter( new QgsProcessingParameterBoolean( QStringLiteral( "USE_HTML" ), QObject::tr( "Use HTML formatting" ), false ) ); | ||
} | ||
|
||
QVariantMap QgsSaveLogToFileAlgorithm::processAlgorithm( const QVariantMap ¶meters, QgsProcessingContext &context, QgsProcessingFeedback *feedback ) | ||
{ | ||
const QString file = parameterAsFile( parameters, QStringLiteral( "OUTPUT" ), context ); | ||
const bool useHtml = parameterAsBool( parameters, QStringLiteral( "USE_HTML" ), context ); | ||
if ( !file.isEmpty() ) | ||
{ | ||
QFile exportFile( file ); | ||
if ( !exportFile.open( QIODevice::WriteOnly | QIODevice::Truncate ) ) | ||
{ | ||
throw QgsProcessingException( QObject::tr( "Could not save log to file %1" ).arg( file ) ); | ||
} | ||
QTextStream fout( &exportFile ); | ||
fout << ( useHtml ? feedback->htmlLog() : feedback->textLog() ); | ||
} | ||
QVariantMap res; | ||
res.insert( QStringLiteral( "OUTPUT" ), file ); | ||
return res; | ||
} | ||
|
||
///@endcond |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/*************************************************************************** | ||
qgsalgorithmsavelog.h | ||
--------------------- | ||
begin : March 2020 | ||
copyright : (C) 2020 by Nyall Dawson | ||
email : nyall dot dawson at gmail dot com | ||
***************************************************************************/ | ||
|
||
/*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#ifndef QGSALGORITHMSAVELOG_H | ||
#define QGSALGORITHMSAVELOG_H | ||
|
||
#define SIP_NO_FILE | ||
|
||
#include "qgis_sip.h" | ||
#include "qgsprocessingalgorithm.h" | ||
#include "qgsapplication.h" | ||
|
||
///@cond PRIVATE | ||
|
||
/** | ||
* Native save log to file algorithm. | ||
*/ | ||
class QgsSaveLogToFileAlgorithm : public QgsProcessingAlgorithm | ||
{ | ||
public: | ||
QgsSaveLogToFileAlgorithm() = default; | ||
void initAlgorithm( const QVariantMap &configuration = QVariantMap() ) override; | ||
Flags flags() const override; | ||
QString name() const override; | ||
QString displayName() const override; | ||
QStringList tags() const override; | ||
QString group() const override; | ||
QString groupId() const override; | ||
QString shortHelpString() const override; | ||
QString shortDescription() const override; | ||
QgsSaveLogToFileAlgorithm *createInstance() const override SIP_FACTORY; | ||
|
||
protected: | ||
|
||
QVariantMap processAlgorithm( const QVariantMap ¶meters, | ||
QgsProcessingContext &context, QgsProcessingFeedback * ) override; | ||
|
||
}; | ||
|
||
|
||
///@endcond PRIVATE | ||
|
||
#endif // QGSALGORITHMSAVELOG_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters