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:
41
test/mmtty.c
41
test/mmtty.c
@@ -23,7 +23,7 @@
|
||||
#include <glib.h>
|
||||
#include <gio/gio.h>
|
||||
|
||||
#include <mm-log-test.h>
|
||||
#include <mm-log.h>
|
||||
#include <mm-port-serial.h>
|
||||
#include <mm-port-serial-at.h>
|
||||
#include <mm-serial-parsers.h>
|
||||
@@ -242,6 +242,45 @@ start_cb (void)
|
||||
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)
|
||||
{
|
||||
GOptionContext *context;
|
||||
|
Reference in New Issue
Block a user