From 9d6ff2485ad1145bb4239027ed594190e8d4df7b Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Wed, 31 Mar 2021 11:00:55 +0200 Subject: 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. --- test/mmtty.c | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) (limited to 'test') 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 #include -#include +#include #include #include #include @@ -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; -- cgit v1.2.3-70-g09d2