Adding a helper function to turn the log level into the text. Also add an internal flag to disable this output. This flag will become useful when adding systemd journal support. --- src/mm-log.c | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-)
diff --git a/src/mm-log.c b/src/mm-log.c index e0255c3..ec622dc 100644 --- a/src/mm-log.c +++ b/src/mm-log.c @@ -48,6 +48,7 @@ static guint32 log_level = LOGL_INFO | LOGL_WARN | LOGL_ERR; static GTimeVal rel_start = { 0, 0 }; static int logfd = -1; static gboolean func_loc = FALSE; +static gboolean append_log_level_text = TRUE; typedef struct { guint32 num; @@ -81,6 +82,24 @@ mm_to_syslog_priority(int level) return LOG_INFO; } +static const char * +log_level_description(int level) +{ + switch (level) { + case LOGL_DEBUG: + return "debug"; + case LOGL_WARN: + return "warn"; + case LOGL_INFO: + return "info"; + case LOGL_ERR: + return "error"; + } + /* this should not happen as all valid enum values are supported + above */ + return "unknown"; +} + void _mm_log (const char *loc, const char *func, @@ -101,20 +120,8 @@ _mm_log (const char *loc, } else g_string_truncate (msgbuf, 0); - switch (level) { - case LOGL_DEBUG: - g_string_append (msgbuf, "<debug> "); - break; - case LOGL_INFO: - g_string_append (msgbuf, "<info> "); - break; - case LOGL_WARN: - g_string_append (msgbuf, "<warn> "); - break; - case LOGL_ERR: - g_string_append (msgbuf, "<error> "); - break; - } + if (append_log_level_text) + g_string_append_printf (msgbuf, "<%s> ", log_level_description(level)); if (ts_flags == TS_FLAG_WALL) { g_get_current_time (&tv); -- 2.7.4 _______________________________________________ ModemManager-devel mailing list ModemManager-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/modemmanager-devel