aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAleksander Morgado <aleksander@aleksander.es>2021-03-31 11:00:55 +0200
committerAleksander Morgado <aleksander@aleksander.es>2021-03-31 13:55:52 +0200
commit9d6ff2485ad1145bb4239027ed594190e8d4df7b (patch)
tree71e0f11dfc1f07be50dcf236a4481ac45b57f382 /test
parent3ca80d8e512061728ed02d66e06b77ac384a9766 (diff)
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.
Diffstat (limited to 'test')
-rw-r--r--test/mmtty.c41
1 files changed, 40 insertions, 1 deletions
diff --git a/test/mmtty.c b/test/mmtty.c
index 7bffd3c0..398eb22b 100644
--- a/test/mmtty.c
+++ b/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;