diff options
author | Torsten Hilbrich <torsten.hilbrich@secunet.com> | 2017-06-21 12:54:36 +0200 |
---|---|---|
committer | Aleksander Morgado <aleksander@aleksander.es> | 2017-06-21 13:04:24 +0200 |
commit | 9160f4e35096fcb99fd6f713861f8f433ef6fbf2 (patch) | |
tree | fec7eb63c5a6a15606d0859834f5db0252a5efb5 /src/mm-log.c | |
parent | b4ad1e8a21c1b175eb2459939120c5fb1fef2c08 (diff) |
log: Refactor log level text output
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.
Diffstat (limited to 'src/mm-log.c')
-rw-r--r-- | src/mm-log.c | 34 |
1 files changed, 20 insertions, 14 deletions
diff --git a/src/mm-log.c b/src/mm-log.c index 4f882f34..eea0bac2 100644 --- a/src/mm-log.c +++ b/src/mm-log.c @@ -47,6 +47,7 @@ static gboolean ts_flags = TS_FLAG_NONE; static guint32 log_level = MM_LOG_LEVEL_INFO | MM_LOG_LEVEL_WARN | MM_LOG_LEVEL_ERR; static GTimeVal rel_start = { 0, 0 }; static int logfd = -1; +static gboolean append_log_level_text = TRUE; typedef struct { guint32 num; @@ -81,6 +82,23 @@ mm_to_syslog_priority (MMLogLevel level) return 0; } +static const char * +log_level_description (MMLogLevel level) +{ + switch (level) { + case MM_LOG_LEVEL_DEBUG: + return "<debug>"; + case MM_LOG_LEVEL_WARN: + return "<warn> "; + case MM_LOG_LEVEL_INFO: + return "<info> "; + case MM_LOG_LEVEL_ERR: + return "<error>"; + } + g_assert_not_reached(); + return NULL; +} + void _mm_log (const char *loc, const char *func, @@ -101,20 +119,8 @@ _mm_log (const char *loc, } else g_string_truncate (msgbuf, 0); - switch (level) { - case MM_LOG_LEVEL_DEBUG: - g_string_append (msgbuf, "<debug> "); - break; - case MM_LOG_LEVEL_INFO: - g_string_append (msgbuf, "<info> "); - break; - case MM_LOG_LEVEL_WARN: - g_string_append (msgbuf, "<warn> "); - break; - case MM_LOG_LEVEL_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); |