[PATCH 2/5] log: Refactor log level text output
Torsten Hilbrich
torsten.hilbrich at secunet.com
Mon May 22 05:49:16 UTC 2017
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
More information about the ModemManager-devel
mailing list