summaryrefslogtreecommitdiffstats
path: root/src/loggerEngine.cpp
blob: 9121af54f54f7b58319ec2399ff73a255ca6b4a3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include "loggerEngine.h"

// --------------------------------------------------------------------------------------------------
//                   Custom Logger Engine for debugging on framebuffer
//---------------------------------------------------------------------------------------------------
loggerEngine_fb::loggerEngine_fb(QTextEdit *parent) : QxtLoggerEngine(){
	// TODO: silly parent storing ... to change!
	_debugConsole = parent;
	_initialized = false;
	setLogLevelsEnabled(QxtLogger::DebugLevel);
	enableLogging();
}
loggerEngine_fb::~loggerEngine_fb(){}

void loggerEngine_fb::initLoggerEngine(){
	_initialized = true;
	return;
}

void loggerEngine_fb::killLoggerEngine(){return;}

void loggerEngine_fb::setLogLevelEnabled(QxtLogger::LogLevels level, bool enable){
    QxtLoggerEngine::setLogLevelsEnabled(level, enable);
    if (!enable) QxtLoggerEngine::setLogLevelsEnabled(QxtLogger::DebugLevel);
}
bool loggerEngine_fb::isInitialized() const{
	return _initialized;
}

void loggerEngine_fb::writeFormatted(QxtLogger::LogLevel level, const QList<QVariant> & msgs){
	// TODO: handle different log levels
	if (msgs.isEmpty()) return;
	Q_FOREACH(const QVariant& out, msgs)
	{
		if (!out.isNull())
			_debugConsole->insertPlainText(out.toString());
	}
	_debugConsole->insertPlainText(QString("\n"));
	// autoscroll
	QTextCursor c = _debugConsole->textCursor();
	c.movePosition(QTextCursor::End);
	_debugConsole->setTextCursor(c);
}
//---------------------------------------------------------------------------------------------------
//                              Modified QxtBasicSTDLoggerEngine
//---------------------------------------------------------------------------------------------------
loggerEngine_std::loggerEngine_std() : QxtBasicSTDLoggerEngine(){}

loggerEngine_std::~loggerEngine_std(){}

void loggerEngine_std::writeToStdErr(const QString& str_level, const QList<QVariant> &msgs){
	if (msgs.isEmpty()) return;
	QString header = '[' + QTime::currentTime().toString("hh:mm:ss.zzz") + "] ";
    QTextStream* errstream = stdErrStream();
    Q_ASSERT(errstream);
    *errstream << header;
    Q_FOREACH(const QVariant& out, msgs)
    {
    	if (!out.isNull())
        	*errstream << out.toString();
    }
    *errstream << endl;
}
void loggerEngine_std::writeToStdOut(const QString& level, const QList<QVariant> & msgs){
	// reimplementing this is needed for compiling,
	// we only need write to std::err, so this function is not needed
}