summaryrefslogtreecommitdiffstats
path: root/src/loggerEngine.cpp
blob: c6c60e4ca8a52448d3ce564f57027449da29f3e6 (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
68
69
70
71
72
73
74
75
76
#include "loggerEngine.h"

loggerEngine_fb::loggerEngine_fb(QTextEdit *parent) : QxtLoggerEngine(){
	_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 */
	/* write the messages to the debug console */
	if (msgs.isEmpty()) return;
	Q_FOREACH(const QVariant& out, msgs)
	{
		if (!out.isNull())
			_debugConsole->insertPlainText(out.toString());
	}
	_debugConsole->insertPlainText(QString("\n"));
	/* move to end of the document */
	QTextCursor c = _debugConsole->textCursor();
	c.movePosition(QTextCursor::End);
	_debugConsole->setTextCursor(c);
}
//----------------------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------------------
loggerEngine_std::loggerEngine_std() : QxtBasicSTDLoggerEngine(){
	setLogLevelsEnabled(QxtLogger::DebugLevel);
	enableLogging();
}
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") + "] [" + str_level + "] ";
    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){
	if (msgs.isEmpty()) return;
	QString header = '[' + QTime::currentTime().toString("hh:mm:ss.zzz") + "] [" + level + "] ";
	QTextStream* outstream = stdOutStream();
	Q_ASSERT(outstream);
	*outstream << header;
	Q_FOREACH(const QVariant& out, msgs){
    	if (!out.isNull()){
        	*outstream << out.toString();
    	}
	}
	*outstream << endl;
}