From 42ddefe8166dc5fc3514a96d5da683fa7a308a87 Mon Sep 17 00:00:00 2001 From: Mark Stapp Date: Wed, 24 Mar 2021 13:57:11 -0400 Subject: [PATCH 1/2] libs: add api to enable immediate output of zlog The log module buffers outgoing messages by default; add an api to turn that off, and emit messages immediately. Signed-off-by: Mark Stapp --- lib/zlog.c | 15 ++++++++++++++- lib/zlog.h | 3 +++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/zlog.c b/lib/zlog.c index 24800c6e64..a99fd71f0d 100644 --- a/lib/zlog.c +++ b/lib/zlog.c @@ -81,6 +81,11 @@ static gid_t zlog_gid = -1; DECLARE_ATOMLIST(zlog_targets, struct zlog_target, head); static struct zlog_targets_head zlog_targets; +/* Global setting for buffered vs immediate output. The default is + * per-pthread buffering. + */ +static bool default_immediate; + /* cf. zlog.h for additional comments on this struct. * * Note: you MUST NOT pass the format string + va_list to non-FRR format @@ -395,7 +400,7 @@ static void vzlog_tls(struct zlog_tls *zlog_tls, const struct xref_logmsg *xref, struct zlog_msg *msg; char *buf; bool ignoremsg = true; - bool immediate = false; + bool immediate = default_immediate; /* avoid further processing cost if no target wants this message */ rcu_read_lock(); @@ -714,6 +719,14 @@ struct zlog_target *zlog_target_replace(struct zlog_target *oldzt, return oldzt; } +/* + * Enable or disable 'immediate' output - default is to buffer + * each pthread's messages. + */ +void zlog_set_immediate(bool set_p) +{ + default_immediate = set_p; +} /* common init */ diff --git a/lib/zlog.h b/lib/zlog.h index 66d8f1e5d7..2ef4173605 100644 --- a/lib/zlog.h +++ b/lib/zlog.h @@ -249,6 +249,9 @@ extern void zlog_tls_buffer_init(void); extern void zlog_tls_buffer_flush(void); extern void zlog_tls_buffer_fini(void); +/* Enable or disable 'immediate' output - default is to buffer messages. */ +extern void zlog_set_immediate(bool set_p); + #ifdef __cplusplus } #endif From 7c945dff610ae526d536b752becdd1555c0d4bfb Mon Sep 17 00:00:00 2001 From: Mark Stapp Date: Thu, 15 Apr 2021 10:25:30 -0400 Subject: [PATCH 2/2] lib: add 'log immediate-mode' cli Add a cli to control immediate-output mode for logs and debugs. Add this to the user docs also. Signed-off-by: Mark Stapp --- doc/user/basic.rst | 6 ++++++ lib/log_vty.c | 13 +++++++++++++ 2 files changed, 19 insertions(+) diff --git a/doc/user/basic.rst b/doc/user/basic.rst index 519f30d5e6..2def835f0b 100644 --- a/doc/user/basic.rst +++ b/doc/user/basic.rst @@ -188,6 +188,12 @@ Basic Config Commands This command clears all current filters in the log-filter table. Can be daemon independent. + +.. clicmd:: log immediate-mode + + Use unbuffered output for log and debug messages; normally there is + some internal buffering. + .. clicmd:: service password-encryption Encrypt password. diff --git a/lib/log_vty.c b/lib/log_vty.c index c6788dd35a..9dbf216d31 100644 --- a/lib/log_vty.c +++ b/lib/log_vty.c @@ -647,6 +647,18 @@ DEFPY (show_log_filter, return CMD_SUCCESS; } +/* Enable/disable 'immediate' mode, with no output buffering */ +DEFPY (log_immediate_mode, + log_immediate_mode_cmd, + "[no] log immediate-mode", + NO_STR + "Logging control" + "Output immediately, without buffering") +{ + zlog_set_immediate(!no); + return CMD_SUCCESS; +} + void log_config_write(struct vty *vty) { bool show_cmdline_hint = false; @@ -775,4 +787,5 @@ void log_cmd_init(void) install_element(CONFIG_NODE, &log_filter_clear_cmd); install_element(CONFIG_NODE, &config_log_filterfile_cmd); install_element(CONFIG_NODE, &no_config_log_filterfile_cmd); + install_element(CONFIG_NODE, &log_immediate_mode_cmd); }