diff options
author | Lubomir Rintel <lkundrak@v3.sk> | 2017-03-01 13:34:32 +0100 |
---|---|---|
committer | Lubomir Rintel <lkundrak@v3.sk> | 2017-03-24 12:42:09 +0100 |
commit | 03a3fd901486aa40b41f2aa066ce1ea832f0f965 (patch) | |
tree | 100ebb67156b2da0748634e629ec818f52faaf0f /src | |
parent | b11b6038792a3da3f47717129580d7c661140291 (diff) | |
download | NetworkManager-03a3fd901486aa40b41f2aa066ce1ea832f0f965.tar.gz |
logging: respect choice of journal/syslog even with --debug
Previously, the daemon would just use syslog with LOG_PERROR when run with
--debug option, even when actually configured to log into the journal.
Let's respect the configuration, but preserve the logging to stderr.
Diffstat (limited to 'src')
-rw-r--r-- | src/main.c | 11 | ||||
-rw-r--r-- | src/nm-iface-helper.c | 5 | ||||
-rw-r--r-- | src/nm-logging.c | 16 | ||||
-rw-r--r-- | src/nm-logging.h | 2 |
4 files changed, 18 insertions, 16 deletions
diff --git a/src/main.c b/src/main.c index 23c05f2952..56b14c9144 100644 --- a/src/main.c +++ b/src/main.c @@ -348,12 +348,11 @@ main (int argc, char *argv[]) /* Set up unix signal handling - before creating threads, but after daemonizing! */ nm_main_utils_setup_signals (main_loop); - nm_logging_syslog_openlog (nm_config_get_is_debug (config) - ? "debug" - : nm_config_data_get_value_cached (NM_CONFIG_GET_DATA_ORIG, - NM_CONFIG_KEYFILE_GROUP_LOGGING, - NM_CONFIG_KEYFILE_KEY_LOGGING_BACKEND, - NM_CONFIG_GET_VALUE_STRIP | NM_CONFIG_GET_VALUE_NO_EMPTY)); + nm_logging_syslog_openlog (nm_config_data_get_value_cached (NM_CONFIG_GET_DATA_ORIG, + NM_CONFIG_KEYFILE_GROUP_LOGGING, + NM_CONFIG_KEYFILE_KEY_LOGGING_BACKEND, + NM_CONFIG_GET_VALUE_STRIP | NM_CONFIG_GET_VALUE_NO_EMPTY), + nm_config_get_is_debug (config)); nm_log_info (LOGD_CORE, "NetworkManager (version " NM_DIST_VERSION ") is starting..."); diff --git a/src/nm-iface-helper.c b/src/nm-iface-helper.c index 4405c32542..6c09467e4a 100644 --- a/src/nm-iface-helper.c +++ b/src/nm-iface-helper.c @@ -432,9 +432,8 @@ main (int argc, char *argv[]) gl.main_loop = g_main_loop_new (NULL, FALSE); setup_signals (); - nm_logging_syslog_openlog (global_opt.logging_backend - ? global_opt.logging_backend - : (global_opt.debug ? "debug" : NULL)); + nm_logging_syslog_openlog (global_opt.logging_backend, + global_opt.debug); _LOGI (LOGD_CORE, "nm-iface-helper (version " NM_DIST_VERSION ") is starting..."); diff --git a/src/nm-logging.c b/src/nm-logging.c index c242d90319..757e117ac9 100644 --- a/src/nm-logging.c +++ b/src/nm-logging.c @@ -94,6 +94,7 @@ static struct Global { NMLogLevel log_level; bool uses_syslog:1; bool syslog_identifier_initialized:1; + bool debug_stderr:1; const char *prefix; const char *syslog_identifier; enum { @@ -630,6 +631,9 @@ _nm_log_impl (const char *file, g_get_current_time (&tv); + if (global.debug_stderr) + g_printerr (MESSAGE_FMT"\n", MESSAGE_ARG (global, tv, msg)); + switch (global.log_backend) { #if SYSTEMD_JOURNAL case LOG_BACKEND_JOURNAL: @@ -817,7 +821,7 @@ nm_logging_set_prefix (const char *format, ...) } void -nm_logging_syslog_openlog (const char *logging_backend) +nm_logging_syslog_openlog (const char *logging_backend, gboolean debug) { if (global.log_backend != LOG_BACKEND_GLIB) g_return_if_reached (); @@ -825,21 +829,21 @@ nm_logging_syslog_openlog (const char *logging_backend) if (!logging_backend) logging_backend = ""NM_CONFIG_DEFAULT_LOGGING_BACKEND; - if (strcmp (logging_backend, "debug") == 0) { - global.log_backend = LOG_BACKEND_SYSLOG; - openlog (syslog_identifier_domain (&global), LOG_CONS | LOG_PERROR | LOG_PID, LOG_USER); #if SYSTEMD_JOURNAL - } else if (strcmp (logging_backend, "syslog") != 0) { + if (strcmp (logging_backend, "syslog") != 0) { global.log_backend = LOG_BACKEND_JOURNAL; global.uses_syslog = TRUE; + global.debug_stderr = debug; /* ensure we read a monotonic timestamp. Reading the timestamp the first * time causes a logging message. We don't want to do that during _nm_log_impl. */ nm_utils_get_monotonic_timestamp_ns (); + } else #endif - } else { + { global.log_backend = LOG_BACKEND_SYSLOG; global.uses_syslog = TRUE; + global.debug_stderr = debug; openlog (syslog_identifier_domain (&global), LOG_PID, LOG_DAEMON); } diff --git a/src/nm-logging.h b/src/nm-logging.h index 2c1a1059a3..990fd31f5f 100644 --- a/src/nm-logging.h +++ b/src/nm-logging.h @@ -191,7 +191,7 @@ gboolean nm_logging_setup (const char *level, void nm_logging_set_syslog_identifier (const char *domain); void nm_logging_set_prefix (const char *format, ...) _nm_printf (1, 2); -void nm_logging_syslog_openlog (const char *logging_backend); +void nm_logging_syslog_openlog (const char *logging_backend, gboolean debug); gboolean nm_logging_syslog_enabled (void); /*****************************************************************************/ |