Added Utils::error() and Utils::info() to print to stderr/stdout instead of qDebug()

Bu işleme şunda yer alıyor:
Albert S. 2019-04-10 18:57:27 +02:00
ebeveyn 6da823d7f3
işleme 9ae74b476a
7 değiştirilmiş dosya ile 45 ekleme ve 20 silme

Dosyayı Görüntüle

@ -44,7 +44,7 @@ QSqlDatabase Command::dbConnection()
db.setDatabaseName(this->dbConnectionString); db.setDatabaseName(this->dbConnectionString);
if(!db.open()) if(!db.open())
{ {
qDebug() << "Failed to open the database: " << this->dbConnectionString; Utils::error() << "Failed to open the database: " << this->dbConnectionString;
} }
dbStore.setLocalData(db); dbStore.setLocalData(db);
return db; return db;

Dosyayı Görüntüle

@ -5,6 +5,7 @@
#include <QSqlQuery> #include <QSqlQuery>
#include <QThreadStorage> #include <QThreadStorage>
#include <QVariant> #include <QVariant>
#include "utils.h"
class Command class Command
{ {
protected: protected:

Dosyayı Görüntüle

@ -71,7 +71,7 @@ AddFileResult CommandAdd::addFile(QString path)
if(pageData.isEmpty()) if(pageData.isEmpty())
{ {
qDebug() << "Could not get any content for " << absPath; Utils::error() << "Could not get any content for " << absPath << endl;
} }
@ -79,7 +79,7 @@ AddFileResult CommandAdd::addFile(QString path)
//QMutexLocker locker(&writeMutex); //QMutexLocker locker(&writeMutex);
if(!db.transaction()) if(!db.transaction())
{ {
qDebug() << "Failed to open transaction for " << absPath << " : " << db.lastError(); Utils::error() << "Failed to open transaction for " << absPath << " : " << db.lastError() << endl;
return DBFAIL; return DBFAIL;
} }
@ -87,7 +87,7 @@ AddFileResult CommandAdd::addFile(QString path)
delQuery.addBindValue(absPath); delQuery.addBindValue(absPath);
if(!delQuery.exec()) if(!delQuery.exec())
{ {
qDebug() << "Failed DELETE query" << delQuery.lastError(); Utils::error() << "Failed DELETE query" << delQuery.lastError() << endl;
db.rollback(); db.rollback();
return DBFAIL; return DBFAIL;
} }
@ -100,7 +100,7 @@ AddFileResult CommandAdd::addFile(QString path)
inserterQuery.addBindValue(fileType); inserterQuery.addBindValue(fileType);
if(!inserterQuery.exec()) if(!inserterQuery.exec())
{ {
qDebug() << "Failed INSERT query" << inserterQuery.lastError(); Utils::error() << "Failed INSERT query" << inserterQuery.lastError() << endl;
db.rollback(); db.rollback();
return DBFAIL; return DBFAIL;
} }
@ -114,7 +114,7 @@ AddFileResult CommandAdd::addFile(QString path)
if(!contentQuery.exec()) if(!contentQuery.exec())
{ {
db.rollback(); db.rollback();
qDebug() << "Failed content insertion " << contentQuery.lastError(); Utils::error() << "Failed content insertion " << contentQuery.lastError() << endl;
return DBFAIL; return DBFAIL;
} }
} }
@ -122,7 +122,7 @@ AddFileResult CommandAdd::addFile(QString path)
if(!db.commit()) if(!db.commit())
{ {
db.rollback(); db.rollback();
qDebug() << "Failed to commit transaction for " << absPath << " : " << db.lastError(); Utils::error() << "Failed to commit transaction for " << absPath << " : " << db.lastError() << endl;
return DBFAIL; return DBFAIL;
} }
return OK; return OK;
@ -184,12 +184,12 @@ int CommandAdd::handle(QStringList arguments)
} }
if(verbose) if(verbose)
{ {
qDebug() << "Processing " << path; Utils::info() << "Processing " << path << endl;
} }
auto result = addFile(path); auto result = addFile(path);
if(result == DBFAIL) if(result == DBFAIL)
{ {
qDebug() << "Failed to add " << path; Utils::error() << "Failed to add " << path << endl;
if(!keepGoing) if(!keepGoing)
{ {
terminate = true; terminate = true;
@ -199,11 +199,11 @@ int CommandAdd::handle(QStringList arguments)
{ {
if(result == SKIPPED) if(result == SKIPPED)
{ {
qDebug() << "Skipped" << path << "as it already exists in the database"; Utils::info() << "Skipped" << path << "as it already exists in the database" << endl;
} }
else else
{ {
qDebug() << "Added" << path; Utils::info() << "Added" << path << endl;
} }
} }

Dosyayı Görüntüle

@ -23,7 +23,7 @@ int CommandDelete::removeNonExistent(QSqlDatabase &db, bool verbose, bool dryRun
QSqlQuery pathsQuery("SELECT path FROM file", db); QSqlQuery pathsQuery("SELECT path FROM file", db);
if(!pathsQuery.exec()) if(!pathsQuery.exec())
{ {
qDebug() << "Failed to query current paths"; Utils::error() << "Failed to query current paths" << endl;
return 1; return 1;
} }
@ -46,17 +46,17 @@ int CommandDelete::removeNonExistent(QSqlDatabase &db, bool verbose, bool dryRun
query.addBindValue(path); query.addBindValue(path);
if(!query.exec()) if(!query.exec())
{ {
qDebug() << "Failed to delete " << path << query.lastError(); Utils::error() << "Failed to delete " << path << query.lastError() << endl;
return 1; return 1;
} }
if(verbose) if(verbose)
{ {
qInfo() << "Deleted " << path; Utils::info() << "Deleted " << path << endl;
} }
} }
else else
{ {
qInfo() << "Would delete " << path; Utils::info() << "Would delete " << path << endl;
} }
} }
@ -81,12 +81,12 @@ int CommandDelete::removePaths(const QStringList &paths, QSqlDatabase &db, bool
{ {
if(verbose) if(verbose)
{ {
qInfo() << "Deleted" << absPath; Utils::info() << "Deleted" << absPath << endl;
} }
} }
else else
{ {
qDebug() << "Failed to delete:" << absPath << deletionQuery.lastError(); Utils::error()<< "Failed to delete:" << absPath << deletionQuery.lastError() << endl;
result = 1; result = 1;
} }
} }
@ -94,7 +94,7 @@ int CommandDelete::removePaths(const QStringList &paths, QSqlDatabase &db, bool
} }
else else
{ {
qInfo() << "No such file in database:" << absPath; Utils::error() << "No such file in database:" << absPath << endl;
result = 1; result = 1;
} }
} }

Dosyayı Görüntüle

@ -15,6 +15,7 @@
#include "encodingdetector.h" #include "encodingdetector.h"
#include "pdfprocessor.h" #include "pdfprocessor.h"
#include "defaulttextprocessor.h" #include "defaulttextprocessor.h"
#include "utils.h"
#include "command.h" #include "command.h"
#include "commandadd.h" #include "commandadd.h"
#include "commanddelete.h" #include "commanddelete.h"
@ -66,12 +67,12 @@ int main(int argc, char *argv[])
} }
catch(const QSSGeneralException &e) catch(const QSSGeneralException &e)
{ {
qDebug() << "Exception caught, message: " << e.message; Utils::error() << "Exception caught, message: " << e.message << endl;
} }
} }
else else
{ {
qDebug() << "Unknown command " << commandName; Utils::error() << "Unknown command " << commandName << endl;
} }
return 1; return 1;
} }

Dosyayı Görüntüle

@ -19,3 +19,23 @@ QByteArray Utils::readFile(QString path)
} }
return data; return data;
} }
QDebug &Utils::info()
{
static QDebug result = []{
QFile *file = new QFile();
file->open(stderr, QIODevice::WriteOnly);
return QDebug(file);
}();
return result;
}
QDebug &Utils::error()
{
static QDebug result = []{
QFile *file = new QFile();
file->open(stdout, QIODevice::WriteOnly);
return QDebug(file);
}();
return result;
}

Dosyayı Görüntüle

@ -3,6 +3,7 @@
#include <QFile> #include <QFile>
#include <QString> #include <QString>
#include <QByteArray> #include <QByteArray>
#include <QTextStream>
#include "qssgeneralexception.h" #include "qssgeneralexception.h"
class Utils class Utils
@ -10,6 +11,8 @@ class Utils
public: public:
Utils(); Utils();
static QByteArray readFile(QString path); static QByteArray readFile(QString path);
static QDebug &info();
static QDebug &error();
}; };
#endif // UTILS_H #endif // UTILS_H