From 51a1b87480973792fcadb35767d7b61f32d12df9 Mon Sep 17 00:00:00 2001 From: Jonathan Bauer Date: Sun, 24 Apr 2011 16:59:50 +0200 Subject: auto-close removed, handled by fbgui nowmake --- src/loggerengine.cpp | 51 +++++++++++++++++++++++++++++++++++++++------------ src/loggerengine.h | 13 ++++++++++++- src/main.cpp | 9 ++++++++- 3 files changed, 59 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/loggerengine.cpp b/src/loggerengine.cpp index 51fba62..3a44159 100644 --- a/src/loggerengine.cpp +++ b/src/loggerengine.cpp @@ -32,8 +32,8 @@ bool LoggerEngine_fb::isInitialized() const { return true; } -void LoggerEngine_fb::writeFormatted(QxtLogger::LogLevel level, const QList< - QVariant> & msgs) { +void LoggerEngine_fb::writeFormatted(QxtLogger::LogLevel level, + const QList & msgs) { // ignore in case no messages was passed. if (msgs.isEmpty()) @@ -47,10 +47,10 @@ void LoggerEngine_fb::writeFormatted(QxtLogger::LogLevel level, const QList< // only write to console for debug level if (level == QxtLogger::DebugLevel) { Q_FOREACH(const QVariant& out, msgs) - { - if (!out.isNull()) - _debugConsole->insertPlainText(out.toString()); - } + { + if (!out.isNull()) + _debugConsole->insertPlainText(out.toString()); + } _debugConsole->insertPlainText(QString("\n")); // autoscroll QTextCursor c = _debugConsole->textCursor(); @@ -68,8 +68,8 @@ LoggerEngine_std::LoggerEngine_std() : LoggerEngine_std::~LoggerEngine_std() { } -void LoggerEngine_std::writeToStdErr(const QString& str_level, const QList< - QVariant> &msgs) { +void LoggerEngine_std::writeToStdErr(const QString& str_level, + const QList &msgs) { if (msgs.isEmpty()) return; @@ -78,10 +78,10 @@ void LoggerEngine_std::writeToStdErr(const QString& str_level, const QList< Q_ASSERT(errstream); *errstream << header; Q_FOREACH(const QVariant& out, msgs) - { - if (!out.isNull()) - *errstream << out.toString(); - } + { + if (!out.isNull()) + *errstream << out.toString(); + } *errstream << endl; } void LoggerEngine_std::writeToStdOut(const QString& level, @@ -89,3 +89,30 @@ void LoggerEngine_std::writeToStdOut(const QString& level, // 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() : + QxtBasicFileLoggerEngine() { +} + +LoggerEngine_file::~LoggerEngine_file() { +} + +LoggerEngine_file::initLoggerEngine() {} + +void LoggerEngine_file::writeToFile(const QString& str_level, + const QList &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"); +} diff --git a/src/loggerengine.h b/src/loggerengine.h index 95a8f93..45f6827 100644 --- a/src/loggerengine.h +++ b/src/loggerengine.h @@ -49,9 +49,20 @@ public: LoggerEngine_std(); ~LoggerEngine_std(); - // reimplemented virtual functions of QxtBasicSTDLoggerEngineqqq + // reimplemented virtual functions of QxtBasicSTDLoggerEngine void writeToStdOut(const QString& level, const QList &msgs); void writeToStdErr(const QString& str_level, const QList &msgs); }; +//--------------------------------------------------------------------------------------------------- +// slighty modified QxtBasicFileLoggerEngine +//--------------------------------------------------------------------------------------------------- +class LoggerEngine_file: public QxtBasicFileLoggerEngine { +public: + LoggerEngine_file(); + ~LoggerEngine_file(); + + // reimplemented virtual functions of QxtBasicFileLoggerEngine + void writeToFile(const QString& level, const QList &msgs); +}; #endif // LOGGERENGINE_H_ diff --git a/src/main.cpp b/src/main.cpp index 9b0a18a..601a62e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -88,13 +88,20 @@ int main(int argc, char *argv[]) { if (clOpts.contains("debug")) { debugMode = clOpts.value("debug").toInt(); - // start basic debug log + // start basic debug output on terminal qxtLog->disableLoggerEngine("DEFAULT"); qxtLog->addLoggerEngine("std_logger", new LoggerEngine_std); qxtLog->initLoggerEngine("std_logger"); qxtLog->setMinimumLevel("std_logger", QxtLogger::DebugLevel); qxtLog->enableLogLevels(QxtLogger::DebugLevel); qxtLog->debug() << "Initializing fbgui..."; + // start debug logging to file. + qxtLog->addLoggerEngine("file_logger", new LoggerEngine_file); + + //qxtLog->initLoggerEngine("std_logger"); + //qxtLog->setMinimumLevel("std_logger", QxtLogger::DebugLevel); + //qxtLog->enableLogLevels(QxtLogger::DebugLevel); + } else debugMode = -1; -- cgit v1.2.3-55-g7522