From 518ab031c29f36095578c8819e0befa503d1ae1d Mon Sep 17 00:00:00 2001 From: Jonathan Bauer Date: Sun, 24 Apr 2011 17:28:07 +0200 Subject: new logger engine to output in file, configurable per cmdline / config file --- fbgui.conf | 1 + src/downloadmanager.cpp | 1 - src/fbgui.cpp | 1 + src/fbgui.h | 4 +++- src/loggerengine.cpp | 8 +++++--- src/loggerengine.h | 4 +++- src/main.cpp | 43 +++++++++++++++++++++++++++++-------------- 7 files changed, 42 insertions(+), 20 deletions(-) diff --git a/fbgui.conf b/fbgui.conf index ac2cecb..8c79c8f 100644 --- a/fbgui.conf +++ b/fbgui.conf @@ -5,3 +5,4 @@ update_interval=5 file_trigger=/tmp/fbgui_trigger serial_location=/serial ip_config=/tmp/ip_config +log_file=/tmp/fbgui.log diff --git a/src/downloadmanager.cpp b/src/downloadmanager.cpp index 7458b4c..adbedd1 100644 --- a/src/downloadmanager.cpp +++ b/src/downloadmanager.cpp @@ -1,5 +1,4 @@ #include "downloadmanager.h" -#include "fbgui.h" int DownloadManager::downloaded = 0; // ------------------------------------------------------------------------------------------------------- diff --git a/src/fbgui.cpp b/src/fbgui.cpp index e3c2d3a..3494b83 100644 --- a/src/fbgui.cpp +++ b/src/fbgui.cpp @@ -11,6 +11,7 @@ #include QThread dmThread; +QString logFilePath(""); QString ipConfigFilePath(""); QString binPath(""); QUrl baseURL(""); diff --git a/src/fbgui.h b/src/fbgui.h index 48ddce4..98ab4c4 100644 --- a/src/fbgui.h +++ b/src/fbgui.h @@ -26,13 +26,15 @@ // Internal default settings #define DEFAULT_URL "http://www.google.com" -#define DEFAULT_DOWNLOAD_DIR "/tmp/fbgui/downloads" +#define DEFAULT_DOWNLOAD_DIR "/tmp/fbgui" #define DEFAULT_CONFIG_PATH "/etc/fbgui.conf" +#define DEFAULT_LOG_FILE_PATH "/tmp/fbgui.log" #define DEFAULT_UPDATE_INTERVAL 1; #define DEFAULT_QRC_HTML_DIR ":/html" #define DEFAULT_FILE_TRIGGER "/tmp/fbgui/trigger" // Global settings variables +extern QString logFilePath; extern QString ipConfigFilePath; extern QThread dmThread; extern QString serialLocation; diff --git a/src/loggerengine.cpp b/src/loggerengine.cpp index 3a44159..fd44633 100644 --- a/src/loggerengine.cpp +++ b/src/loggerengine.cpp @@ -92,14 +92,16 @@ void LoggerEngine_std::writeToStdOut(const QString& level, //--------------------------------------------------------------------------------------------------- // slighty modified QxtBasicFileLoggerEngine //--------------------------------------------------------------------------------------------------- -LoggerEngine_file::LoggerEngine_file() : - QxtBasicFileLoggerEngine() { +LoggerEngine_file::LoggerEngine_file(const QString& logFileName) : + QxtBasicFileLoggerEngine(logFileName) { + //setLogFileName(logFileName); } LoggerEngine_file::~LoggerEngine_file() { } -LoggerEngine_file::initLoggerEngine() {} +void LoggerEngine_file::initLoggerEngine() { +} void LoggerEngine_file::writeToFile(const QString& str_level, const QList &msgs) { diff --git a/src/loggerengine.h b/src/loggerengine.h index 45f6827..94cf59e 100644 --- a/src/loggerengine.h +++ b/src/loggerengine.h @@ -20,6 +20,7 @@ #include #include #include + //--------------------------------------------------------------------------------------------------- // base of a custom logger engine for the framebuffer //--------------------------------------------------------------------------------------------------- @@ -58,8 +59,9 @@ public: //--------------------------------------------------------------------------------------------------- class LoggerEngine_file: public QxtBasicFileLoggerEngine { public: - LoggerEngine_file(); + LoggerEngine_file(const QString& logFileName); ~LoggerEngine_file(); + void initLoggerEngine(); // reimplemented virtual functions of QxtBasicFileLoggerEngine void writeToFile(const QString& level, const QList &msgs); diff --git a/src/main.cpp b/src/main.cpp index 601a62e..24e0430 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -54,13 +54,17 @@ int main(int argc, char *argv[]) { NULL, 'c' }, { "url", required_argument, NULL, 'u' }, { "download", required_argument, NULL, 'd' }, { "serial", required_argument, NULL, 's' }, { "trigger", required_argument, NULL, 't' }, { "debug", - required_argument, NULL, 'D' }, { "help", no_argument, NULL, 'h' } }; + required_argument, NULL, 'D' }, { "help", no_argument, NULL, 'h' }, { + "logfile", required_argument, NULL, 'l' } }; int opt = getopt_long(argc, argv, optString, longOpts, &longIndex); while (opt != -1) { switch (opt) { case 'c': clOpts.insert("configFile", optarg); break; + case 'l': + clOpts.insert("logFile", optarg); + break; case 'u': clOpts.insert("url", optarg); break; @@ -90,18 +94,10 @@ int main(int argc, char *argv[]) { debugMode = clOpts.value("debug").toInt(); // start basic debug output on terminal qxtLog->disableLoggerEngine("DEFAULT"); + qxtLog->enableLogLevels(QxtLogger::DebugLevel); 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; @@ -175,12 +171,27 @@ int main(int argc, char *argv[]) { // save ip config location (file generated by uchpc) if (confFileSettings.contains("default/ip_config")) ipConfigFilePath = confFileSettings.value("default/ip_config").toString(); - //else - // ipConfigFilePath = QString("/tmp/ip_config"); + + // save path to log file + if (clOpts.contains("logFile")) + logFilePath = clOpts.value("logFile"); + else if (confFileSettings.contains("default/log_file")) + logFilePath = confFileSettings.value("default/log_file").toString(); + else + logFilePath = DEFAULT_LOG_FILE_PATH; + + // activate file logger if debug mode activated. + if (debugMode > -1) { + // start debug logging to file. + qxtLog->addLoggerEngine("file_logger", + new LoggerEngine_file(logFilePath)); + qxtLog->setMinimumLevel("file_logger", QxtLogger::DebugLevel); + } // print config qxtLog->debug() << "************* CONFIG INFO *************"; qxtLog->debug() << "configFilePath: " << configFilePath.toUtf8(); + qxtLog->debug() << "logFilePath: " << logFilePath.toUtf8(); qxtLog->debug() << "ipConfigFilePath:" << ipConfigFilePath.toUtf8(); qxtLog->debug() << "baseURL: " << baseURL.toString().toUtf8(); qxtLog->debug() << "downloadDir : " << downloadPath.toUtf8(); @@ -190,9 +201,13 @@ int main(int argc, char *argv[]) { // set invisible cursor QWSServer::instance()->setCursorVisible(false); - QWSServer::instance()->setDefaultKeyboard("TTY:/dev/tty0"); - QWSServer::instance()->setDefaultMouse("IntelliMouse:/dev/mice"); + + // set default keyboard / mouse drivers. TODO: fix this, doesn't work... + //QWSServer::instance()->setDefaultKeyboard("TTY:/dev/tty0"); + //QWSServer::instance()->setDefaultMouse("IntelliMouse:/dev/mice"); + // start fbgui + qxtLog->debug() << "Initializing fbgui..."; fbgui gui; gui.show(); return app.exec(); -- cgit v1.2.3-55-g7522