test,mmsmspdu: fix verbose logging support

This commit is contained in:
Aleksander Morgado
2023-03-30 19:36:14 +00:00
parent 5656d01099
commit 7ec71020e7

View File

@@ -26,7 +26,8 @@
#include <ModemManager.h> #include <ModemManager.h>
#define _LIBMM_INSIDE_MM #define _LIBMM_INSIDE_MM
#include <libmm-glib.h> #include <libmm-glib.h>
#include "mm-log-test.h"
#include "mm-log.h"
#include "mm-sms-part-3gpp.h" #include "mm-sms-part-3gpp.h"
#define PROGRAM_NAME "mmsmspdu" #define PROGRAM_NAME "mmsmspdu"
@@ -176,6 +177,45 @@ print_version_and_exit (void)
exit (EXIT_SUCCESS); exit (EXIT_SUCCESS);
} }
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;