summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2015-07-08 17:28:22 +0200
committerThomas Haller <thaller@redhat.com>2015-07-14 15:52:50 +0200
commitb1b26e8049c5041bf3a217f68496778bbfcc7dd5 (patch)
tree88a1d3de69f56fb9b2a7fdac1edf42f56889fbd6
parent831a5e32fb38ec0407b986bee0984142bffbdac8 (diff)
downloadNetworkManager-b1b26e8049c5041bf3a217f68496778bbfcc7dd5.tar.gz
logging: factor our construction of logging message in _nm_log_impl()
-rw-r--r--src/nm-logging.c26
1 files changed, 17 insertions, 9 deletions
diff --git a/src/nm-logging.c b/src/nm-logging.c
index ac418da193..ce1c49e18c 100644
--- a/src/nm-logging.c
+++ b/src/nm-logging.c
@@ -379,6 +379,8 @@ _nm_log_impl (const char *file,
GTimeVal tv;
int syslog_level = LOG_INFO;
int g_log_level = G_LOG_LEVEL_INFO;
+ gboolean full_details = FALSE;
+ const char *level_str = NULL;
g_return_if_fail (level < LOGL_MAX);
@@ -397,38 +399,44 @@ _nm_log_impl (const char *file,
switch (level) {
case LOGL_TRACE:
- g_get_current_time (&tv);
syslog_level = LOG_DEBUG;
g_log_level = G_LOG_LEVEL_DEBUG;
- fullmsg = g_strdup_printf ("<trace> [%ld.%06ld] [%s:%u] %s(): %s", tv.tv_sec, tv.tv_usec, file, line, func, msg);
+ full_details = TRUE;
+ level_str = "<trace>";
break;
case LOGL_DEBUG:
- g_get_current_time (&tv);
syslog_level = LOG_INFO;
g_log_level = G_LOG_LEVEL_DEBUG;
- fullmsg = g_strdup_printf ("<debug> [%ld.%06ld] [%s:%u] %s(): %s", tv.tv_sec, tv.tv_usec, file, line, func, msg);
+ full_details = TRUE;
+ level_str = "<debug>";
break;
case LOGL_INFO:
syslog_level = LOG_INFO;
g_log_level = G_LOG_LEVEL_MESSAGE;
- fullmsg = g_strconcat ("<info> ", msg, NULL);
+ level_str = "<info>";
break;
case LOGL_WARN:
syslog_level = LOG_WARNING;
g_log_level = G_LOG_LEVEL_WARNING;
- fullmsg = g_strconcat ("<warn> ", msg, NULL);
+ level_str = "<warn>";
break;
case LOGL_ERR:
syslog_level = LOG_ERR;
/* g_log_level is still WARNING, because ERROR is fatal */
g_log_level = G_LOG_LEVEL_WARNING;
- g_get_current_time (&tv);
- fullmsg = g_strdup_printf ("<error> [%ld.%06ld] [%s:%u] %s(): %s", tv.tv_sec, tv.tv_usec, file, line, func, msg);
+ full_details = TRUE;
+ level_str = "<error>";
break;
default:
- g_assert_not_reached ();
+ g_return_if_reached ();
}
+ if (full_details) {
+ g_get_current_time (&tv);
+ fullmsg = g_strdup_printf ("%-7s [%ld.%06ld] [%s:%u] %s(): %s", level_str, tv.tv_sec, tv.tv_usec, file, line, func, msg);
+ } else
+ fullmsg = g_strdup_printf ("%-7s %s", level_str, msg);
+
switch (log_backend) {
case LOG_BACKEND_SYSLOG:
syslog (syslog_level, "%s", fullmsg);