diff options
| author | Niklas | 2011-06-28 10:51:08 +0200 |
|---|---|---|
| committer | Niklas | 2011-06-28 10:51:08 +0200 |
| commit | 2842ca3160966ed1633f9d6605531e18b435de61 (patch) | |
| tree | d705e55b3307985da28307e24b7ac33a0e024cce /src/loggerengine.cpp | |
| parent | added the networkDiscovery project into a new workspace folder (diff) | |
| parent | build.sh dummy (diff) | |
| download | fbgui-2842ca3160966ed1633f9d6605531e18b435de61.tar.gz fbgui-2842ca3160966ed1633f9d6605531e18b435de61.tar.xz fbgui-2842ca3160966ed1633f9d6605531e18b435de61.zip | |
Merge branch 'master' of git.openslx.org:lsfks/projekte/fbgui
Diffstat (limited to 'src/loggerengine.cpp')
| -rw-r--r-- | src/loggerengine.cpp | 134 |
1 files changed, 82 insertions, 52 deletions
diff --git a/src/loggerengine.cpp b/src/loggerengine.cpp index d37999d..8a0991d 100644 --- a/src/loggerengine.cpp +++ b/src/loggerengine.cpp @@ -4,83 +4,113 @@ // base of a custom logger engine for the framebuffer //--------------------------------------------------------------------------------------------------- LoggerEngine_fb::LoggerEngine_fb(QTextEdit *parent) : - QxtLoggerEngine() { - _debugConsole = parent; - //_initialized = false; - //setLogLevelsEnabled(QxtLogger::DebugLevel); - //enableLogging(); + QxtLoggerEngine() { + _debugConsole = parent; + //_initialized = false; + //setLogLevelsEnabled(QxtLogger::DebugLevel); + //enableLogging(); } LoggerEngine_fb::~LoggerEngine_fb() { } void LoggerEngine_fb::initLoggerEngine() { - //_initialized = true; - return; + //_initialized = true; + return; } void LoggerEngine_fb::killLoggerEngine() { - return; + return; } -void LoggerEngine_fb::setLogLevelEnabled(QxtLogger::LogLevels level, - bool enable) { - //QxtLoggerEngine::setLogLevelsEnabled(level, enable); - //if (!enable) QxtLoggerEngine::setLogLevelsEnabled(QxtLogger::DebugLevel); +void LoggerEngine_fb::setLogLevelEnabled(QxtLogger::LogLevels, bool) { + //QxtLoggerEngine::setLogLevelsEnabled(level, enable); + //if (!enable) QxtLoggerEngine::setLogLevelsEnabled(QxtLogger::DebugLevel); } bool LoggerEngine_fb::isInitialized() const { - //return _initialized; - return true; + //return _initialized; + return true; } -void LoggerEngine_fb::writeFormatted(QxtLogger::LogLevel level, - const QList<QVariant> & msgs) { +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); - } + // ignore in case no messages was passed. + if (msgs.isEmpty()) + return; + + // write timestamp header in format: [hh:mm:ss.zzz] + // example: [23:58:99.999] + 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() { + QxtBasicSTDLoggerEngine() { } LoggerEngine_std::~LoggerEngine_std() { } -void LoggerEngine_std::writeToStdErr(const QString& str_level, - const QList<QVariant> &msgs) { +void LoggerEngine_std::writeToStdErr(const QString&, 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; + 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&, const QList<QVariant> &) { + // (level, msgs) + // reimplementing this is needed for compiling, + // we only need write to std::err, so this function is not needed +} +//--------------------------------------------------------------------------------------------------- +// slighty modified QxtBasicFileLoggerEngine +//--------------------------------------------------------------------------------------------------- +LoggerEngine_file::LoggerEngine_file(const QString& logFileName) : + QxtBasicFileLoggerEngine(logFileName) { + //setLogFileName(logFileName); +} + +LoggerEngine_file::~LoggerEngine_file() { } -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 + +void LoggerEngine_file::initLoggerEngine() { +} + +void LoggerEngine_file::writeToFile(const QString&, const QList<QVariant> &msgs) { + + if (msgs.isEmpty()) + return; + QIODevice* file = device(); + QString header = '[' + QTime::currentTime().toString("hh:mm:ss.zzz") + "] "; + file->write(header.toUtf8()); + Q_FOREACH(const QVariant& out, msgs) + { + if (!out.isNull()) + file->write(out.toString().toUtf8()); + } + file->write("\n"); } |
