summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDonatas Abraitis <donatas@opensourcerouting.org>2024-01-19 10:56:15 +0200
committerGitHub <noreply@github.com>2024-01-19 10:56:15 +0200
commit2844d093b562b9befb653c86e8b5e41e51e31b4d (patch)
tree63574b8f7482999b29b8ebabead32b0ea8353615
parent6103c6251ac7986cda4d538d25efc5fcc2b6d1c7 (diff)
parentc7f7cf96101dc958cff10d37bbed6635dcb25caf (diff)
Merge pull request #15168 from mjstapp/daemon_logs
lib,vtysh: add per-daemon log file config
-rw-r--r--doc/user/basic.rst14
-rw-r--r--lib/.gitignore1
-rw-r--r--lib/log_vty.c67
-rw-r--r--lib/subdir.am10
-rw-r--r--vtysh/.gitignore1
-rw-r--r--vtysh/subdir.am10
-rw-r--r--vtysh/vtysh.c2
7 files changed, 93 insertions, 12 deletions
diff --git a/doc/user/basic.rst b/doc/user/basic.rst
index 4fd4f5f7c4..55b836e3b8 100644
--- a/doc/user/basic.rst
+++ b/doc/user/basic.rst
@@ -129,6 +129,20 @@ Basic Config Commands
deprecated ``log trap`` command) will be used. The ``no`` form of the command
disables logging to a file.
+.. clicmd:: log daemon DAEMON file [FILENAME [LEVEL]]
+
+ Configure file logging for a single FRR daemon. If you want to log
+ into a file, please specify ``filename`` as in this example:
+
+ ::
+
+ log daemon bgpd file /var/log/frr/bgpd.log informational
+
+ If the optional second argument specifying the logging level is not present,
+ the default logging level (typically debugging, but can be changed using the
+ deprecated ``log trap`` command) will be used. The ``no`` form of the command
+ disables logging to a file for a single FRR daemon.
+
.. clicmd:: log syslog [LEVEL]
Enable logging output to syslog. If the optional second argument specifying
diff --git a/lib/.gitignore b/lib/.gitignore
index 6176b30f8d..5d38469ca2 100644
--- a/lib/.gitignore
+++ b/lib/.gitignore
@@ -11,3 +11,4 @@
/grammar_sandbox
/clippy
/defun_lex.c
+vtysh_daemons.h
diff --git a/lib/log_vty.c b/lib/log_vty.c
index fc298533ae..1ce25196da 100644
--- a/lib/log_vty.c
+++ b/lib/log_vty.c
@@ -15,6 +15,7 @@
#include "lib/lib_errors.h"
#include "lib/printfrr.h"
#include "lib/systemd.h"
+#include "lib/vtysh_daemons.h"
#include "lib/log_vty_clippy.c"
@@ -459,6 +460,70 @@ DEFUN (clear_log_cmdline,
return CMD_SUCCESS;
}
+/* Per-daemon log file config */
+DEFUN (config_log_dmn_file,
+ config_log_dmn_file_cmd,
+ "log daemon " DAEMONS_LIST " file FILENAME [<emergencies|alerts|critical|errors|warnings|notifications|informational|debugging>$levelarg]",
+ "Logging control\n"
+ "Specific daemon\n"
+ DAEMONS_STR
+ "Logging to file\n"
+ "Logging filename\n"
+ LOG_LEVEL_DESC)
+{
+ int level = log_default_lvl;
+ int idx = 0;
+ const char *d_str;
+ const char *filename;
+ const char *levelarg = NULL;
+
+ d_str = argv[2]->text;
+
+ /* Ignore if not for this daemon */
+ if (!strmatch(d_str, frr_get_progname()))
+ return CMD_SUCCESS;
+
+ if (argv_find(argv, argc, "file", &idx))
+ filename = argv[idx + 1]->arg;
+ else
+ return CMD_SUCCESS;
+
+ if (argc > 5)
+ levelarg = argv[5]->text;
+
+ if (levelarg) {
+ level = log_level_match(levelarg);
+ if (level == ZLOG_DISABLED)
+ return CMD_ERR_NO_MATCH;
+ }
+ return set_log_file(&zt_file, vty, filename, level);
+}
+
+/* Per-daemon no log file */
+DEFUN (no_config_log_dmn_file,
+ no_config_log_dmn_file_cmd,
+ "no log daemon " DAEMONS_LIST " file [FILENAME [LEVEL]]",
+ NO_STR
+ "Logging control\n"
+ "Specific daemon\n"
+ DAEMONS_STR
+ "Cancel logging to file\n"
+ "Logging file name\n"
+ "Logging level\n")
+{
+ const char *d_str;
+
+ d_str = argv[3]->text;
+
+ /* Ignore if not for this daemon */
+ if (!strmatch(d_str, frr_get_progname()))
+ return CMD_SUCCESS;
+
+ zt_file.prio_min = ZLOG_DISABLED;
+ zlog_file_set_other(&zt_file);
+ return CMD_SUCCESS;
+}
+
DEFPY (config_log_file,
config_log_file_cmd,
"log file FILENAME [<emergencies|alerts|critical|errors|warnings|notifications|informational|debugging>$levelarg]",
@@ -904,6 +969,8 @@ void log_cmd_init(void)
install_element(CONFIG_NODE, &config_log_monitor_cmd);
install_element(CONFIG_NODE, &no_config_log_monitor_cmd);
install_element(CONFIG_NODE, &config_log_file_cmd);
+ install_element(CONFIG_NODE, &config_log_dmn_file_cmd);
+ install_element(CONFIG_NODE, &no_config_log_dmn_file_cmd);
install_element(CONFIG_NODE, &no_config_log_file_cmd);
install_element(CONFIG_NODE, &config_log_syslog_cmd);
install_element(CONFIG_NODE, &no_config_log_syslog_cmd);
diff --git a/lib/subdir.am b/lib/subdir.am
index 4f203c0c84..6893049c7e 100644
--- a/lib/subdir.am
+++ b/lib/subdir.am
@@ -540,12 +540,22 @@ EXTRA_DIST += \
BUILT_SOURCES += \
lib/gitversion.h \
lib/route_types.h \
+ lib/vtysh_daemons.h \
# end
## force route_types.h
$(lib_clippy_OBJECTS): lib/route_types.h
$(lib_libfrr_la_OBJECTS): lib/route_types.h
+# force lib_daemons.h
+$(lib_libfrr_la_OBJECTS): lib/vtysh_daemons.h
+
+CLEANFILES += lib/vtysh_daemons.h
+lib/vtysh_daemons.h:
+ @$(MKDIR_P) lib
+ $(PERL) $(top_srcdir)/vtysh/daemons.pl $(vtysh_daemons) > lib/vtysh_daemons.h
+
+
AM_YFLAGS = -d -Dapi.prefix=@BISON_OPENBRACE@cmd_yy@BISON_CLOSEBRACE@ @BISON_VERBOSE@
lib/command_lex.h: lib/command_lex.c
diff --git a/vtysh/.gitignore b/vtysh/.gitignore
index 09e90e51d2..a6c3d4abc6 100644
--- a/vtysh/.gitignore
+++ b/vtysh/.gitignore
@@ -1,6 +1,5 @@
vtysh
vtysh_cmd.c
-vtysh_daemons.h
# does not exist anymore - remove 2023-10-04 or so
extract.pl
diff --git a/vtysh/subdir.am b/vtysh/subdir.am
index a1b81f598a..2eae16d629 100644
--- a/vtysh/subdir.am
+++ b/vtysh/subdir.am
@@ -29,13 +29,3 @@ noinst_HEADERS += \
vtysh_vtysh_LDADD = lib/libfrr.la $(LIBCAP) $(LIBREADLINE) $(LIBS) $(LIBPAM)
EXTRA_DIST += vtysh/daemons.pl
-
-BUILT_SOURCES += vtysh/vtysh_daemons.h
-
-# force vtysh_daemons.h
-$(vtysh_vtysh_OBJECTS): vtysh/vtysh_daemons.h
-
-CLEANFILES += vtysh/vtysh_daemons.h
-vtysh/vtysh_daemons.h:
- @$(MKDIR_P) vtysh
- $(PERL) $(top_srcdir)/vtysh/daemons.pl $(vtysh_daemons) > vtysh/vtysh_daemons.h
diff --git a/vtysh/vtysh.c b/vtysh/vtysh.c
index 2888403e62..d5ac87eb32 100644
--- a/vtysh/vtysh.c
+++ b/vtysh/vtysh.c
@@ -31,7 +31,7 @@
#include "network.h"
#include "filter.h"
#include "vtysh/vtysh.h"
-#include "vtysh/vtysh_daemons.h"
+#include "lib/vtysh_daemons.h"
#include "log.h"
#include "vrf.h"
#include "libfrr.h"