Commit 03a3fd90 authored by Lubomir Rintel's avatar Lubomir Rintel 🥕
Browse files

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.
parent b11b6038
...@@ -348,12 +348,11 @@ main (int argc, char *argv[]) ...@@ -348,12 +348,11 @@ main (int argc, char *argv[])
/* Set up unix signal handling - before creating threads, but after daemonizing! */ /* Set up unix signal handling - before creating threads, but after daemonizing! */
nm_main_utils_setup_signals (main_loop); nm_main_utils_setup_signals (main_loop);
nm_logging_syslog_openlog (nm_config_get_is_debug (config) nm_logging_syslog_openlog (nm_config_data_get_value_cached (NM_CONFIG_GET_DATA_ORIG,
? "debug" NM_CONFIG_KEYFILE_GROUP_LOGGING,
: nm_config_data_get_value_cached (NM_CONFIG_GET_DATA_ORIG, NM_CONFIG_KEYFILE_KEY_LOGGING_BACKEND,
NM_CONFIG_KEYFILE_GROUP_LOGGING, NM_CONFIG_GET_VALUE_STRIP | NM_CONFIG_GET_VALUE_NO_EMPTY),
NM_CONFIG_KEYFILE_KEY_LOGGING_BACKEND, nm_config_get_is_debug (config));
NM_CONFIG_GET_VALUE_STRIP | NM_CONFIG_GET_VALUE_NO_EMPTY));
nm_log_info (LOGD_CORE, "NetworkManager (version " NM_DIST_VERSION ") is starting..."); nm_log_info (LOGD_CORE, "NetworkManager (version " NM_DIST_VERSION ") is starting...");
......
...@@ -432,9 +432,8 @@ main (int argc, char *argv[]) ...@@ -432,9 +432,8 @@ main (int argc, char *argv[])
gl.main_loop = g_main_loop_new (NULL, FALSE); gl.main_loop = g_main_loop_new (NULL, FALSE);
setup_signals (); setup_signals ();
nm_logging_syslog_openlog (global_opt.logging_backend nm_logging_syslog_openlog (global_opt.logging_backend,
? global_opt.logging_backend global_opt.debug);
: (global_opt.debug ? "debug" : NULL));
_LOGI (LOGD_CORE, "nm-iface-helper (version " NM_DIST_VERSION ") is starting..."); _LOGI (LOGD_CORE, "nm-iface-helper (version " NM_DIST_VERSION ") is starting...");
......
...@@ -94,6 +94,7 @@ static struct Global { ...@@ -94,6 +94,7 @@ static struct Global {
NMLogLevel log_level; NMLogLevel log_level;
bool uses_syslog:1; bool uses_syslog:1;
bool syslog_identifier_initialized:1; bool syslog_identifier_initialized:1;
bool debug_stderr:1;
const char *prefix; const char *prefix;
const char *syslog_identifier; const char *syslog_identifier;
enum { enum {
...@@ -630,6 +631,9 @@ _nm_log_impl (const char *file, ...@@ -630,6 +631,9 @@ _nm_log_impl (const char *file,
g_get_current_time (&tv); g_get_current_time (&tv);
if (global.debug_stderr)
g_printerr (MESSAGE_FMT"\n", MESSAGE_ARG (global, tv, msg));
switch (global.log_backend) { switch (global.log_backend) {
#if SYSTEMD_JOURNAL #if SYSTEMD_JOURNAL
case LOG_BACKEND_JOURNAL: case LOG_BACKEND_JOURNAL:
...@@ -817,7 +821,7 @@ nm_logging_set_prefix (const char *format, ...) ...@@ -817,7 +821,7 @@ nm_logging_set_prefix (const char *format, ...)
} }
void 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) if (global.log_backend != LOG_BACKEND_GLIB)
g_return_if_reached (); g_return_if_reached ();
...@@ -825,21 +829,21 @@ nm_logging_syslog_openlog (const char *logging_backend) ...@@ -825,21 +829,21 @@ nm_logging_syslog_openlog (const char *logging_backend)
if (!logging_backend) if (!logging_backend)
logging_backend = ""NM_CONFIG_DEFAULT_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 #if SYSTEMD_JOURNAL
} else if (strcmp (logging_backend, "syslog") != 0) { if (strcmp (logging_backend, "syslog") != 0) {
global.log_backend = LOG_BACKEND_JOURNAL; global.log_backend = LOG_BACKEND_JOURNAL;
global.uses_syslog = TRUE; global.uses_syslog = TRUE;
global.debug_stderr = debug;
/* ensure we read a monotonic timestamp. Reading the timestamp the first /* 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. */ * time causes a logging message. We don't want to do that during _nm_log_impl. */
nm_utils_get_monotonic_timestamp_ns (); nm_utils_get_monotonic_timestamp_ns ();
} else
#endif #endif
} else { {
global.log_backend = LOG_BACKEND_SYSLOG; global.log_backend = LOG_BACKEND_SYSLOG;
global.uses_syslog = TRUE; global.uses_syslog = TRUE;
global.debug_stderr = debug;
openlog (syslog_identifier_domain (&global), LOG_PID, LOG_DAEMON); openlog (syslog_identifier_domain (&global), LOG_PID, LOG_DAEMON);
} }
......
...@@ -191,7 +191,7 @@ gboolean nm_logging_setup (const char *level, ...@@ -191,7 +191,7 @@ gboolean nm_logging_setup (const char *level,
void nm_logging_set_syslog_identifier (const char *domain); void nm_logging_set_syslog_identifier (const char *domain);
void nm_logging_set_prefix (const char *format, ...) _nm_printf (1, 2); 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); gboolean nm_logging_syslog_enabled (void);
/*****************************************************************************/ /*****************************************************************************/
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment