projects
/
pulseview.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
INSTALL: Bump libsigrokdecode requirement to >= 0.6.0.
[pulseview.git]
/
pv
/
logging.cpp
diff --git
a/pv/logging.cpp
b/pv/logging.cpp
index 9740690e7f33e87364a4a915c22499127b3f0cc2..b747ab5452c5f4ee7b2aef633a65fc1e02986f47 100644
(file)
--- a/
pv/logging.cpp
+++ b/
pv/logging.cpp
@@
-20,6
+20,8
@@
#include "logging.hpp"
#include "globalsettings.hpp"
#include "logging.hpp"
#include "globalsettings.hpp"
+#include <iostream>
+
#ifdef ENABLE_DECODE
#include <libsigrokdecode/libsigrokdecode.h> /* First, so we avoid a _POSIX_C_SOURCE warning. */
#endif
#ifdef ENABLE_DECODE
#include <libsigrokdecode/libsigrokdecode.h> /* First, so we avoid a _POSIX_C_SOURCE warning. */
#endif
@@
-28,18
+30,37
@@
#include <QApplication>
#include <QApplication>
+using std::cout;
+using std::endl;
+using std::lock_guard;
+
namespace pv {
Logging logging;
namespace pv {
Logging logging;
+const int Logging::MIN_BUFFER_SIZE = 10;
const int Logging::MAX_BUFFER_SIZE = 50000;
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);
Logging::~Logging()
{
qInstallMessageHandler(nullptr);
- sr_log_callback_set_default();
+ if (prev_sr_log_cb)
+ sr_log_callback_set(prev_sr_log_cb, prev_sr_log_cb_data);
+ prev_sr_log_cb = nullptr;
+ prev_sr_log_cb_data = nullptr;
#ifdef ENABLE_DECODE
#ifdef ENABLE_DECODE
- srd_log_callback_set_default();
+ if (prev_srd_log_cb)
+ srd_log_callback_set(prev_srd_log_cb, prev_srd_log_cb_data);
+ prev_srd_log_cb = nullptr;
+ prev_srd_log_cb_data = nullptr;
#endif
GlobalSettings::remove_change_handler(this);
#endif
GlobalSettings::remove_change_handler(this);
@@
-55,8
+76,10
@@
void Logging::init()
buffer_.reserve(buffer_size_);
qInstallMessageHandler(log_pv);
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
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
srd_log_callback_set(log_srd, nullptr);
#endif
@@
-72,7
+95,9
@@
int Logging::get_log_level() const
void Logging::set_log_level(int level)
{
sr_log_loglevel_set(level);
void Logging::set_log_level(int level)
{
sr_log_loglevel_set(level);
+#ifdef ENABLE_DECODE
srd_log_loglevel_set(level);
srd_log_loglevel_set(level);
+#endif
}
QString Logging::get_log() const
}
QString Logging::get_log() const
@@
-82,6
+107,8
@@
QString Logging::get_log() const
void Logging::log(const QString &text, int source)
{
void Logging::log(const QString &text, int source)
{
+ lock_guard<mutex> log_lock(log_mutex_);
+
if (buffer_.size() >= buffer_size_)
buffer_.removeFirst();
if (buffer_.size() >= buffer_size_)
buffer_.removeFirst();
@@
-99,10
+126,10
@@
void Logging::log(const QString &text, int source)
switch (source) {
case LogSource_pv:
switch (source) {
case LogSource_pv:
- s = QString("
pv: ") + text; // black is default color
+ s = QString("
<font color=\"darkMagenta\">pv: %1</font>").arg(text);
break;
case LogSource_sr:
break;
case LogSource_sr:
- s = QString("<font color=\"
blue
\">sr: %1</font>").arg(text);
+ s = QString("<font color=\"
darkGreen
\">sr: %1</font>").arg(text);
break;
case LogSource_srd:
s = QString("<font color=\"olive\">srd: %1</font>").arg(text);
break;
case LogSource_srd:
s = QString("<font color=\"olive\">srd: %1</font>").arg(text);
@@
-127,12
+154,20
@@
void Logging::log_pv(QtMsgType type, const QMessageLogContext &context, const QS
(void)context;
logging.log(msg, LogSource_pv);
(void)context;
logging.log(msg, LogSource_pv);
+
+ cout << msg.toUtf8().data() << endl;
}
int Logging::log_sr(void *cb_data, int loglevel, const char *format, va_list args)
{
}
int Logging::log_sr(void *cb_data, int loglevel, const char *format, va_list args)
{
+ va_list args2;
+
(void)cb_data;
(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);
char *text = g_strdup_vprintf(format, args);
logging.log(QString::fromUtf8(text), LogSource_sr);
@@
-144,8
+179,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)
{
#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)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);
char *text = g_strdup_vprintf(format, args);
logging.log(QString::fromUtf8(text), LogSource_srd);