summaryrefslogtreecommitdiffstats
path: root/src/loggerengine.cpp
blob: d37999da0fafee6a59139393e54668c0560a82f8 (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
77
78
79
80
81
82
83
84
85
86
#include "loggerengine.h"

// --------------------------------------------------------------------------------------------------
//                       base of a custom logger engine for the framebuffer
//---------------------------------------------------------------------------------------------------
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;
    return true;
}

void LoggerEngine_fb::writeFormatted(QxtLogger::LogLevel level,
        const QList<QVariant> & msgs) {

    if (msgs.isEmpty())
        return;
    QString header = '[' + QTime::currentTime().toString("hh:mm:ss.zzz") + "] ";
    _debugConsole->insertPlainText(header);
    // only write to console for debug level
    if (level == QxtLogger::DebugLevel) {
        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);
    }
}
//---------------------------------------------------------------------------------------------------
//                            slighty 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
}