From 030c8868aba976cc9a7b7e04b09d4095b95ad9b5 Mon Sep 17 00:00:00 2001 From: Bill Somerville Date: Sat, 26 Sep 2020 15:14:51 +0100 Subject: [PATCH] Dump current settings to trace log at startup --- main.cpp | 74 +++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 57 insertions(+), 17 deletions(-) diff --git a/main.cpp b/main.cpp index a52ece821..c1e7715ae 100644 --- a/main.cpp +++ b/main.cpp @@ -2,7 +2,9 @@ #include #include #include - +#include +#include +#include #include #include @@ -63,6 +65,29 @@ namespace } } seeding; #endif + + void safe_stream_QVariant (boost::log::wrecord_ostream& os, QVariant const& v) + { + if (QMetaType::QByteArray == static_cast (v.type ())) + { + auto const& a =v.toByteArray (); + std::ios::fmtflags f (os.flags ()); + os << std::hex << std::showbase; + for (auto p = a.begin (); p != a.end (); ) + { + os << static_cast (*p++); + if (p != a.end ()) + { + os << ' '; + } + } + os.flags (f); + } + else + { + os << v.toString ().toStdWString (); + } + } } int main(int argc, char *argv[]) @@ -291,28 +316,43 @@ int main(int argc, char *argv[]) auto const& original_style_sheet = a.styleSheet (); do { -#if WSJT_QDEBUG_TO_FILE - // announce to trace file and dump settings - qDebug () << "++++++++++++++++++++++++++++ Settings ++++++++++++++++++++++++++++"; - for (auto const& key: multi_settings.settings ()->allKeys ()) + // dump settings + auto sys_lg = Logger::sys::get (); + if (auto rec = sys_lg.open_record + ( + boost::log::keywords::severity = boost::log::trivial::trace) + ) { - auto const& value = multi_settings.settings ()->value (key); - if (value.canConvert ()) + boost::log::wrecord_ostream strm (rec); + strm << "++++++++++++++++++++++++++++ Settings ++++++++++++++++++++++++++++\n"; + for (auto const& key: multi_settings.settings ()->allKeys ()) { - auto const sequence = value.value (); - qDebug ().nospace () << key << ": "; - for (auto const& item: sequence) + if (!key.contains (QRegularExpression {"^MultiSettings/[^/]*/"})) { - qDebug ().nospace () << '\t' << item; + auto const& value = multi_settings.settings ()->value (key); + if (value.canConvert ()) + { + auto const sequence = value.value (); + strm << key.toStdWString () << ":\n"; + for (auto const& item: sequence) + { + strm << "\t"; + safe_stream_QVariant (strm, item); + strm << '\n'; + } + } + else + { + strm << key.toStdWString () << ": "; + safe_stream_QVariant (strm, value); + strm << '\n'; + } } } - else - { - qDebug ().nospace () << key << ": " << value; - } + strm << "---------------------------- Settings ----------------------------\n"; + strm.flush (); + sys_lg.push_record (boost::move (rec)); } - qDebug () << "---------------------------- Settings ----------------------------"; -#endif // Create and initialize shared memory segment // Multiple instances: use rig_name as shared memory key