Commit c92c564c authored by Lisa's avatar Lisa
Browse files

New message hanler used to manage debug prints

parent 46dde954
......@@ -318,6 +318,8 @@ Backend::Backend(QObject* parent)
akabeiDebug() << "Set max thread count to 2";
QThreadPool::globalInstance()->setMaxThreadCount(2);
}
qInstallMsgHandler(akabeiDebug);
}
Backend::~Backend()
......
......@@ -24,6 +24,7 @@ class Config::Private
Private()
: root('/')
, maxCacheSize(0)
, debug(false)
{}
~Private() {}
......@@ -40,6 +41,8 @@ class Config::Private
int maxCacheSize;
Cache::MaxSizePolicy policy;
bool debug;
};
class ConfigHelper
......@@ -138,6 +141,11 @@ Cache::MaxSizePolicy Config::cachePolicy() const
return d->policy;
}
bool Config::debug()
{
return d->debug;
}
void Config::setCachePath(const QString& path)
{
d->cachePath = path;
......@@ -191,5 +199,10 @@ void Config::setCachePolicy(Cache::MaxSizePolicy policy)
d->policy = policy;
}
void Config::setDebug(bool debug)
{
d->debug = debug;
}
}
......@@ -133,6 +133,16 @@ class AKABEICORESHARED_EXPORT Config
* Sets the policy to be applied to the cache
*/
void setCachePolicy(Cache::MaxSizePolicy policy);
/**
* @returns whether to display debugging prints
*/
bool debug();
/**
* Sets whether to display debugging prints
*/
void setDebug(bool debug);
private:
Config();
......
......@@ -8,8 +8,43 @@
version 2 of the License, or (at your option) any later version.
*/
#include "akabeidebug.h"
#include <akabeiconfig.h>
QDebug akabeiDebug()
{
return qDebug() << "Akabei - Debug: ";
return qDebug();
}
void akabeiDebug(QtMsgType type, const char *msg)
{
QTextStream out( stdout );
QTextStream err( stderr );
if (Akabei::Config::instance()->debug()) { /* only prints if the "--debug" option is set */
switch (type) {
case QtDebugMsg: {
out << "Akabei - Debug: " << msg << endl;
break;
}
case QtWarningMsg: {
err << "Akabei - Warning: " << msg << endl;
break;
}
case QtCriticalMsg: {
err << "Akabei - Critical: " << msg << endl;
break;
}
case QtFatalMsg: {
err << "Akabei - Fatal: " << msg << endl;
break;
}
default:
break;
}
}
}
......@@ -11,7 +11,16 @@
#define AKABEIDEBUG_H
#include <QDebug>
#include <akabeicore_global.h>
/**
* Akabei Qt message handler (for qDebug(), qWarning(), ...)
*/
void akabeiDebug(QtMsgType, const char *);
/*
* This is a workaround to avoid changing all the akabeiDebug() calls back into qDebug() calls
*/
QDebug akabeiDebug();
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment