diff options
author | Beniamino Galvani <bgalvani@redhat.com> | 2021-09-07 13:59:34 +0200 |
---|---|---|
committer | Beniamino Galvani <bgalvani@redhat.com> | 2021-09-07 14:02:25 +0200 |
commit | 9dff1c03019ccbe03e4567b0fa32bed93dc6abe4 (patch) | |
tree | 0799616e4ecf91b0a8629c6ec2563dde081eeaea | |
parent | 9b089b34a1e92d55f1b0de95a59bdd3dd7b6feab (diff) | |
download | NetworkManager-bg/log-none.tar.gz |
log: introduce "none" logging backendbg/log-none
In initrd, the NM service should write logs to both the active console
and the journal. To achieve that, NetworkManager is started with
"--debug" to output logs to stderr, and the systemd unit is configured
with "StandardError=tty" to redirect messages to the console. NM is
configured with "logging.backend=journal" to also save logs in the
journal. The problem of this approach is that when the system doesn't
have a console, the NM service fails to start [1].
This can be solved by using "StandardError=journal+console" which
forwards messages from stderr to journald (which in turn also writes
them to the console if available). To avoid duplicates entries in the
journal, we need a way to disable all logging backends in NM and only
write to stderr.
Introduce a "none" logging backend. Of course, it's not recommended to
start NM without logging; therefore the "none" backend can't be used
as build-time default. "none" only makes some sense when also starting
NM with "--debug".
[1] https://github.com/coreos/fedora-coreos-tracker/issues/943
-rw-r--r-- | man/NetworkManager.conf.xml | 12 | ||||
-rw-r--r-- | src/libnm-log-core/nm-logging.c | 12 | ||||
-rw-r--r-- | src/libnm-log-core/nm-logging.h | 1 |
3 files changed, 18 insertions, 7 deletions
diff --git a/man/NetworkManager.conf.xml b/man/NetworkManager.conf.xml index 7eaa4cb2a1..1ebeaabaf4 100644 --- a/man/NetworkManager.conf.xml +++ b/man/NetworkManager.conf.xml @@ -717,11 +717,13 @@ unmanaged-devices=mac:00:22:68:1c:59:b1;mac:00:1E:65:30:D1:C4;interface-name:eth </varlistentry> <varlistentry> <term><varname>backend</varname></term> - <listitem><para>The logging backend. Supported values - are "<literal>syslog</literal>" and "<literal>journal</literal>". - When NetworkManager is started with "<literal>--debug</literal>" - in addition all messages will be printed to stderr. - If unspecified, the default is "<literal>&NM_CONFIG_DEFAULT_LOGGING_BACKEND_TEXT;</literal>". + <listitem><para>The logging backend. Supported values are + "<literal>syslog</literal>", "<literal>journal</literal>" + and "<literal>none</literal>". When NetworkManager is + started with "<literal>--debug</literal>" in addition all + messages will be printed to stderr. If unspecified, the + default is + "<literal>&NM_CONFIG_DEFAULT_LOGGING_BACKEND_TEXT;</literal>". </para></listitem> </varlistentry> <varlistentry> diff --git a/src/libnm-log-core/nm-logging.c b/src/libnm-log-core/nm-logging.c index 6d2c085eee..da82cd0238 100644 --- a/src/libnm-log-core/nm-logging.c +++ b/src/libnm-log-core/nm-logging.c @@ -75,6 +75,7 @@ G_STATIC_ASSERT(sizeof(NMLogDomain) >= sizeof(guint64)); /*****************************************************************************/ typedef enum { + LOG_BACKEND_NONE, LOG_BACKEND_GLIB, LOG_BACKEND_SYSLOG, LOG_BACKEND_JOURNAL, @@ -794,6 +795,8 @@ _nm_log_impl(const char *file, case LOG_BACKEND_SYSLOG: syslog(nm_log_level_desc[level].syslog_level, MESSAGE_FMT, MESSAGE_ARG(g->prefix, tv, msg)); break; + case LOG_BACKEND_NONE: + break; default: g_log(syslog_identifier_domain(g->syslog_identifier), nm_log_level_desc[level].g_log_level, @@ -867,6 +870,8 @@ nm_log_handler(const char *log_domain, GLogLevelFlags level, const char *message g_printerr("%s%s\n", gl.imm.prefix, message ?: ""); switch (gl.imm.log_backend) { + case LOG_BACKEND_NONE: + break; #if SYSTEMD_JOURNAL case LOG_BACKEND_JOURNAL: { @@ -980,8 +985,11 @@ nm_logging_init(const char *logging_backend, gboolean debug) G_LOCK(log); + if (nm_streq(logging_backend, NM_LOG_CONFIG_BACKEND_NONE)) { + x_log_backend = LOG_BACKEND_NONE; + } else #if SYSTEMD_JOURNAL - if (!nm_streq(logging_backend, NM_LOG_CONFIG_BACKEND_SYSLOG)) { + if (!nm_streq(logging_backend, NM_LOG_CONFIG_BACKEND_SYSLOG)) { x_log_backend = LOG_BACKEND_JOURNAL; /* We only log the monotonic-timestamp with structured logging (journal). @@ -1017,7 +1025,7 @@ nm_logging_init(const char *logging_backend, gboolean debug) "config: ignore deprecated logging backend 'debug', fallback to '%s'", logging_backend); - if (nm_streq(logging_backend, NM_LOG_CONFIG_BACKEND_SYSLOG)) { + if (NM_IN_STRSET(logging_backend, NM_LOG_CONFIG_BACKEND_SYSLOG, NM_LOG_CONFIG_BACKEND_NONE)) { /* good */ } else if (nm_streq(logging_backend, NM_LOG_CONFIG_BACKEND_JOURNAL)) { #if !SYSTEMD_JOURNAL diff --git a/src/libnm-log-core/nm-logging.h b/src/libnm-log-core/nm-logging.h index 8071967552..739473a1ad 100644 --- a/src/libnm-log-core/nm-logging.h +++ b/src/libnm-log-core/nm-logging.h @@ -16,6 +16,7 @@ #define NM_LOG_CONFIG_BACKEND_DEBUG "debug" #define NM_LOG_CONFIG_BACKEND_SYSLOG "syslog" #define NM_LOG_CONFIG_BACKEND_JOURNAL "journal" +#define NM_LOG_CONFIG_BACKEND_NONE "none" #define nm_log_err(domain, ...) nm_log(LOGL_ERR, (domain), NULL, NULL, __VA_ARGS__) #define nm_log_warn(domain, ...) nm_log(LOGL_WARN, (domain), NULL, NULL, __VA_ARGS__) |