mmtty: fix printing logs with --verbose

The _mm_log() implementation provided in 'mm-log-test.h' relies on
g_test_verbose() to decide whether the logs are printed or not. We are
not running under the GTest setup in mmtty, so that would not work
properly.

Just provide a custom _mm_log() method that checks for the
verbose_flag instead.
This commit is contained in:
Aleksander Morgado
2021-03-31 11:00:55 +02:00
parent 3ca80d8e51
commit 9d6ff2485a

View File

@@ -23,7 +23,7 @@
#include <glib.h> #include <glib.h>
#include <gio/gio.h> #include <gio/gio.h>
#include <mm-log-test.h> #include <mm-log.h>
#include <mm-port-serial.h> #include <mm-port-serial.h>
#include <mm-port-serial-at.h> #include <mm-port-serial-at.h>
#include <mm-serial-parsers.h> #include <mm-serial-parsers.h>
@@ -242,6 +242,45 @@ start_cb (void)
return G_SOURCE_REMOVE; return G_SOURCE_REMOVE;
} }
void
_mm_log (gpointer obj,
const gchar *module,
const gchar *loc,
const gchar *func,
guint32 level,
const gchar *fmt,
...)
{
va_list args;
g_autofree gchar *msg = NULL;
const gchar *level_str = NULL;
if (!verbose_flag)
return;
switch (level) {
case MM_LOG_LEVEL_DEBUG:
level_str = "debug";
break;
case MM_LOG_LEVEL_WARN:
level_str = "warning";
break;
case MM_LOG_LEVEL_INFO:
level_str = "info";
break;
case MM_LOG_LEVEL_ERR:
level_str = "error";
break;
default:
break;
}
va_start (args, fmt);
msg = g_strdup_vprintf (fmt, args);
va_end (args);
g_print ("[%s] %s\n", level_str ? level_str : "unknown", msg);
}
int main (int argc, char **argv) int main (int argc, char **argv)
{ {
GOptionContext *context; GOptionContext *context;