logging: add compile time default for logging.backend configuration
authorThomas Haller <thaller@redhat.com>
Wed, 8 Jul 2015 19:44:01 +0000 (21:44 +0200)
committerThomas Haller <thaller@redhat.com>
Tue, 14 Jul 2015 13:55:14 +0000 (15:55 +0200)
configure.ac
man/NetworkManager.conf.xml.in
src/nm-logging.c

index 11f6ccd..9d5ad54 100644 (file)
@@ -400,6 +400,26 @@ else
        AC_DEFINE([SYSTEMD_JOURNAL], 0, [Define to 1 if libsystemd-journald is available])
 fi
 
+AC_ARG_WITH(config-logging-backend-default, AS_HELP_STRING([--with-logging-backend-default=backend], [Default value for logging.backend]), nm_config_logging_backend_default="$withval", nm_config_logging_backend_default="")
+if test "$nm_config_logging_backend_default" != 'debug' \
+     -a "$nm_config_logging_backend_default" != 'syslog' \
+     -a "$nm_config_logging_backend_default" != 'journal' \
+     -a "$nm_config_logging_backend_default" != 'journal-syslog-style'; then
+       # unknown backend. Reset to default. Silently accept the invalid value to
+       # be future proof.
+       nm_config_logging_backend_default=''
+fi
+if test "$nm_config_logging_backend_default" = ""; then
+       if test "$have_systemd_journal" = "yes"; then
+               nm_config_logging_backend_default='journal-syslog-style'
+       else
+               nm_config_logging_backend_default='syslog'
+       fi
+fi
+AC_DEFINE_UNQUOTED(NM_CONFIG_LOGGING_BACKEND_DEFAULT, "$nm_config_logging_backend_default", [Default configuration option for logging.backend])
+NM_CONFIG_LOGGING_BACKEND_DEFAULT_TEXT="$nm_config_logging_backend_default"
+AC_SUBST(NM_CONFIG_LOGGING_BACKEND_DEFAULT_TEXT)
+
 # Session tracking support
 AC_ARG_WITH(systemd-logind, AS_HELP_STRING([--with-systemd-logind=yes|no],
        [Support systemd session tracking]))
@@ -1115,7 +1135,7 @@ else
 fi
 echo "  polkit agent: ${enable_polkit_agent}"
 echo "  selinux: $have_selinux"
-echo "  systemd-journald: $have_systemd_journal"
+echo "  systemd-journald: $have_systemd_journal (logging.backend: ${nm_config_logging_backend_default})"
 echo "  hostname persist: ${hostname_persist}"
 echo
 
index 3b30825..4d4c8a2 100644 (file)
@@ -481,8 +481,7 @@ unmanaged-devices=mac:00:22:68:1c:59:b1;mac:00:1E:65:30:D1:C4;interface-name:eth
          fields in the text.
          If NetworkManager is started in debug mode (<literal>--debug</literal>)
          this option is ignored and "<literal>debug</literal>" is always used.
-         Otherwise, the default is "<literal>journal-syslog-style</literal>" if
-         NetworkManager was compiled with systemd journal support.
+         Otherwise, the default is "<literal>@NM_CONFIG_LOGGING_BACKEND_DEFAULT_TEXT@</literal>".
          </para></listitem>
        </varlistentry>
       </variablelist>
index c1a81e0..17d820a 100644 (file)
@@ -640,12 +640,15 @@ nm_logging_syslog_openlog (const char *logging_backend)
        if (log_backend != LOG_BACKEND_GLIB)
                g_return_if_reached ();
 
-       if (g_strcmp0 (logging_backend, "debug") == 0) {
+       if (!logging_backend)
+               logging_backend = ""NM_CONFIG_LOGGING_BACKEND_DEFAULT;
+
+       if (strcmp (logging_backend, "debug") == 0) {
                log_backend = LOG_BACKEND_SYSLOG;
                openlog (G_LOG_DOMAIN, LOG_CONS | LOG_PERROR | LOG_PID, LOG_USER);
 #if SYSTEMD_JOURNAL
-       } else if (g_strcmp0 (logging_backend, "syslog") != 0) {
-               if (g_strcmp0 (logging_backend, "journal-syslog-style") != 0)
+       } else if (strcmp (logging_backend, "syslog") != 0) {
+               if (strcmp (logging_backend, "journal-syslog-style") != 0)
                        log_backend = LOG_BACKEND_JOURNAL;
                else
                        log_backend = LOG_BACKEND_JOURNAL_SYSLOG_STYLE;