core, log: make libraries logging use the MM level and format

The log level of the libraries was not honoring the log level
configured in MM, so we would see debug messages reported even if the
default log level configured was INFO or MSG.

The format of the logs emitted by the libraries was also not following
the format of the rest of MM logs, e.g. they would not include timing
info in the logs which would make it hard to follow certain event
transitions.

Make the libraries logging use the ModemManager logging method, to fix
all those issues.
This commit is contained in:
Aleksander Morgado
2022-08-05 17:11:34 +02:00
parent 4cb8ca8f0b
commit bb310526dc
+16 -11
View File
@@ -96,8 +96,8 @@ mm_to_syslog_priority (MMLogLevel level)
return 0;
}
static int
glib_to_syslog_priority (GLogLevelFlags level)
static MMLogLevel
glib_level_to_mm_level (GLogLevelFlags level)
{
/* if the log was flagged as fatal (e.g. G_DEBUG=fatal-warnings), ignore
* the fatal flag for logging purposes */
@@ -106,17 +106,15 @@ glib_to_syslog_priority (GLogLevelFlags level)
switch (level) {
case G_LOG_LEVEL_ERROR:
return LOG_CRIT;
case G_LOG_LEVEL_CRITICAL:
return LOG_ERR;
return MM_LOG_LEVEL_ERR;
case G_LOG_LEVEL_WARNING:
return LOG_WARNING;
return MM_LOG_LEVEL_WARN;
case G_LOG_LEVEL_MESSAGE:
return LOG_NOTICE;
case G_LOG_LEVEL_INFO:
return LOG_INFO;
return MM_LOG_LEVEL_INFO;
case G_LOG_LEVEL_DEBUG:
return LOG_DEBUG;
return MM_LOG_LEVEL_DEBUG;
case G_LOG_LEVEL_MASK:
case G_LOG_FLAG_FATAL:
case G_LOG_FLAG_RECURSION:
@@ -249,7 +247,8 @@ _mm_log (gpointer obj,
}
#if defined MM_LOG_FUNC_LOC
g_string_append_printf (msgbuf, "[%s] %s(): ", loc, func);
if (loc && func)
g_string_append_printf (msgbuf, "[%s] %s(): ", loc, func);
#endif
if (obj)
@@ -268,11 +267,17 @@ _mm_log (gpointer obj,
static void
log_handler (const gchar *log_domain,
GLogLevelFlags level,
GLogLevelFlags glib_level,
const gchar *message,
gpointer ignored)
{
log_backend (NULL, NULL, glib_to_syslog_priority (level), message, strlen (message));
_mm_log (NULL, /* obj */
NULL, /* module */
NULL, /* loc */
NULL, /* func */
glib_level_to_mm_level (glib_level),
"%s",
message);
}
gboolean