From 79a2a65030d4bfa9e41d5e0c84332421dfa5caed Mon Sep 17 00:00:00 2001 From: Bill Somerville Date: Wed, 6 Apr 2016 17:10:54 +0000 Subject: [PATCH] Improve time stamps in debug trace and dump settings to debug file git-svn-id: svn+ssh://svn.code.sf.net/p/wsjt/wsjt/branches/wsjtx@6582 ab8295b8-cf94-4d9e-aec4-7959e3be5d79 --- main.cpp | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 52 insertions(+), 3 deletions(-) diff --git a/main.cpp b/main.cpp index 752176d4b..36ed7213f 100644 --- a/main.cpp +++ b/main.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #if QT_VERSION >= 0x050200 #include @@ -43,10 +44,39 @@ namespace qsrand (seed); // this is good for rand() as well } } seeding; + + class MessageTimestamper + { + public: + MessageTimestamper () + { + prior_handlers_.push (qInstallMessageHandler (message_handler)); + } + ~MessageTimestamper () + { + if (prior_handlers_.size ()) qInstallMessageHandler (prior_handlers_.pop ()); + } + + private: + static void message_handler (QtMsgType type, QMessageLogContext const& context, QString const& msg) + { + QtMessageHandler handler {prior_handlers_.top ()}; + if (handler) + { + handler (type, context, + QDateTime::currentDateTimeUtc ().toString ("yy-MM-ddTHH:mm:ss.zzzZ: ") + msg); + } + } + static QStack prior_handlers_; + }; + QStack MessageTimestamper::prior_handlers_; } int main(int argc, char *argv[]) { + // Add timestamps to all debug messages + MessageTimestamper message_timestamper; + init_random_seed (); register_types (); // make the Qt magic happen @@ -171,11 +201,30 @@ int main(int argc, char *argv[]) } #if WSJT_QDEBUG_TO_FILE - // // open a trace file + // Open a trace file TraceFile trace_file {QDir {QStandardPaths::writableLocation (QStandardPaths::TempLocation)}.absoluteFilePath (a.applicationName () + "_trace.log")}; - // announce to trace file + // announce to trace file and dump settings qDebug () << program_title (revision ()) + " - Program startup"; + qDebug () << "++++++++++++++++++++++++++++ Settings ++++++++++++++++++++++++++++"; + for (auto const& key: settings.allKeys ()) + { + auto const& value = settings.value (key); + if (value.canConvert ()) + { + auto const sequence = value.value (); + qDebug ().nospace () << key << ": "; + for (auto const& item: sequence) + { + qDebug ().nospace () << '\t' << item; + } + } + else + { + qDebug ().nospace () << key << ": " << value; + } + } + qDebug () << "---------------------------- Settings ----------------------------"; #endif // Create and initialize shared memory segment @@ -207,9 +256,9 @@ int main(int argc, char *argv[]) ).toBool () ? 1u : 4u; } + // run the application UI MainWindow w(multiple, &settings, &mem_jt9, downSampleFactor, new QNetworkAccessManager {&a}); w.show(); - QObject::connect (&a, SIGNAL (lastWindowClosed()), &a, SLOT (quit())); return a.exec(); }