callouts: downgrade logging severity of messages to g_info() and g_debug()
authorThomas Haller <thaller@redhat.com>
Wed, 24 Feb 2016 14:17:02 +0000 (15:17 +0100)
committerThomas Haller <thaller@redhat.com>
Wed, 24 Feb 2016 19:04:29 +0000 (20:04 +0100)
In dispatcher, we install a log-handler which maps G_LOG_LEVEL_MESSAGE
to syslog priority LOG_NOTICE, which in turn causes journal to highlight
the message. We don't want that so instead use g_info() and g_debug()
which maps to lower syslog levels.

There is only one problem, in debug-mode, we don't use syslog but the
default logging handler from glib. In this case, we have to set
G_MESSAGES_DEBUG otherwise g_info()/g_debug() is suppressed.

callouts/nm-dispatcher.c

index 755d581..de13bd0 100644 (file)
@@ -173,12 +173,12 @@ _LOG_R_D_enabled (const Request *request)
        return request->debug;
 }
 
-#define _LOG_R_D(_request, ...) _LOG(_request, NULL, FALSE, g_message, __VA_ARGS__)
-#define _LOG_R_I(_request, ...) _LOG(_request, NULL, TRUE,  g_message, __VA_ARGS__)
+#define _LOG_R_D(_request, ...) _LOG(_request, NULL, FALSE, g_debug,   __VA_ARGS__)
+#define _LOG_R_I(_request, ...) _LOG(_request, NULL, TRUE,  g_info,    __VA_ARGS__)
 #define _LOG_R_W(_request, ...) _LOG(_request, NULL, TRUE,  g_warning, __VA_ARGS__)
 
-#define _LOG_S_D(_script, ...)  _LOG(NULL, _script,  FALSE, g_message, __VA_ARGS__)
-#define _LOG_S_I(_script, ...)  _LOG(NULL, _script,  TRUE,  g_message, __VA_ARGS__)
+#define _LOG_S_D(_script, ...)  _LOG(NULL, _script,  FALSE, g_debug,   __VA_ARGS__)
+#define _LOG_S_I(_script, ...)  _LOG(NULL, _script,  TRUE,  g_info,    __VA_ARGS__)
 #define _LOG_S_W(_script, ...)  _LOG(NULL, _script,  TRUE,  g_warning, __VA_ARGS__)
 
 /*****************************************************************************/
@@ -913,7 +913,16 @@ main (int argc, char **argv)
        g_unix_signal_add (SIGTERM, signal_handler, GINT_TO_POINTER (SIGTERM));
        g_unix_signal_add (SIGINT, signal_handler, GINT_TO_POINTER (SIGINT));
 
-       if (!debug)
+
+       if (debug) {
+               if (!g_getenv ("G_MESSAGES_DEBUG")) {
+                       /* we log our regular messages using g_debug() and g_info().
+                        * When we redirect glib logging to syslog, there is no problem.
+                        * But in "debug" mode, glib will no print these messages unless
+                        * we set G_MESSAGES_DEBUG. */
+                       g_setenv ("G_MESSAGES_DEBUG", "all", TRUE);
+               }
+       } else
                logging_setup ();
 
        loop = g_main_loop_new (NULL, FALSE);