From: Gerhard Sittig Date: Wed, 15 Aug 2018 21:48:52 +0000 (+0200) Subject: Logging: obsolete -s, log to internal buffer as well as stdout X-Git-Url: http://git.code-monkey.de/?p=pulseview.git;a=commitdiff_plain;h=4b9234088f56c5b0e22f8aa5b18ef346285a7fc6 Logging: obsolete -s, log to internal buffer as well as stdout Query the sr and srd libraries' current log routines before registering PV's own log callback which queues messages in an internal buffer. This allows duplication of messages to the internal buffer _and_ stdout, and thus obsoletes the -s option. --- diff --git a/main.cpp b/main.cpp index 780371b..ce12573 100644 --- a/main.cpp +++ b/main.cpp @@ -155,7 +155,6 @@ void usage() " -i, --input-file Load input from file\n" " -I, --input-format Input format\n" " -c, --clean Don't restore previous sessions on startup\n" - " -s, --log-to-stdout Don't use logging, output to stdout instead\n" "\n", PV_BIN_NAME); } @@ -167,7 +166,6 @@ int main(int argc, char *argv[]) vector open_files; bool restore_sessions = true; bool do_scan = true; - bool do_logging = true; Application a(argc, argv); @@ -193,7 +191,7 @@ int main(int argc, char *argv[]) }; const int c = getopt_long(argc, argv, - "h?VDcsl:d:i:I:", long_options, nullptr); + "h?VDcl:d:i:I:", long_options, nullptr); if (c == -1) break; @@ -248,10 +246,6 @@ int main(int argc, char *argv[]) case 'c': restore_sessions = false; break; - - case 's': - do_logging = false; - break; } } argc -= optind; @@ -264,8 +258,7 @@ int main(int argc, char *argv[]) pv::GlobalSettings settings; settings.set_defaults_where_needed(); - if (do_logging) - pv::logging.init(); + pv::logging.init(); // Initialise libsigrok context = sigrok::Context::create(); diff --git a/pv/logging.cpp b/pv/logging.cpp index dea333e..83577af 100644 --- a/pv/logging.cpp +++ b/pv/logging.cpp @@ -37,12 +37,24 @@ Logging logging; const int Logging::MIN_BUFFER_SIZE = 10; const int Logging::MAX_BUFFER_SIZE = 50000; +static sr_log_callback prev_sr_log_cb; +static void *prev_sr_log_cb_data; + +#ifdef ENABLE_DECODE +static srd_log_callback prev_srd_log_cb; +static void *prev_srd_log_cb_data; +#endif + Logging::~Logging() { qInstallMessageHandler(nullptr); - sr_log_callback_set_default(); + sr_log_callback_set(prev_sr_log_cb, prev_sr_log_cb_data); + prev_sr_log_cb = NULL; + prev_sr_log_cb_data = NULL; #ifdef ENABLE_DECODE - srd_log_callback_set_default(); + srd_log_callback_set(prev_srd_log_cb, prev_srd_log_cb_data); + prev_srd_log_cb = NULL; + prev_srd_log_cb_data = NULL; #endif GlobalSettings::remove_change_handler(this); @@ -58,8 +70,10 @@ void Logging::init() buffer_.reserve(buffer_size_); qInstallMessageHandler(log_pv); + sr_log_callback_get(&prev_sr_log_cb, &prev_sr_log_cb_data); sr_log_callback_set(log_sr, nullptr); #ifdef ENABLE_DECODE + srd_log_callback_get(&prev_srd_log_cb, &prev_srd_log_cb_data); srd_log_callback_set(log_srd, nullptr); #endif @@ -138,8 +152,14 @@ void Logging::log_pv(QtMsgType type, const QMessageLogContext &context, const QS int Logging::log_sr(void *cb_data, int loglevel, const char *format, va_list args) { + va_list args2; + (void)cb_data; - (void)loglevel; + + va_copy(args2, args); + if (prev_sr_log_cb) + prev_sr_log_cb(prev_sr_log_cb_data, loglevel, format, args2); + va_end(args2); char *text = g_strdup_vprintf(format, args); logging.log(QString::fromUtf8(text), LogSource_sr); @@ -151,8 +171,14 @@ int Logging::log_sr(void *cb_data, int loglevel, const char *format, va_list arg #ifdef ENABLE_DECODE int Logging::log_srd(void *cb_data, int loglevel, const char *format, va_list args) { + va_list args2; + (void)cb_data; - (void)loglevel; + + va_copy(args2, args); + if (prev_srd_log_cb) + prev_srd_log_cb(prev_srd_log_cb_data, loglevel, format, args2); + va_end(args2); char *text = g_strdup_vprintf(format, args); logging.log(QString::fromUtf8(text), LogSource_srd);