From f8507817cf19d621cefd1d0310925ad07ec4646e Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Fri, 15 Jun 2018 13:38:46 -0400 Subject: lib: Add new cli to specify where to output logs on startup When we are starting a daemon, allow the user to specify: --log This can be used on early startup to put the log files where the end user wants them to show up. Signed-off-by: Donald Sharp --- lib/command.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'lib/command.c') diff --git a/lib/command.c b/lib/command.c index a8e61c6bb4..32b052c36c 100644 --- a/lib/command.c +++ b/lib/command.c @@ -2429,7 +2429,8 @@ static int set_log_file(struct vty *vty, const char *fname, int loglevel) XFREE(MTYPE_TMP, p); if (!ret) { - vty_out(vty, "can't open logfile %s\n", fname); + if (vty) + vty_out(vty, "can't open logfile %s\n", fname); return CMD_WARNING_CONFIG_FAILED; } @@ -2445,6 +2446,26 @@ static int set_log_file(struct vty *vty, const char *fname, int loglevel) return CMD_SUCCESS; } +void command_setup_early_logging(const char *option) +{ + char *token; + + if (strcmp(option, "stdout") == 0) { + zlog_set_level(ZLOG_DEST_STDOUT, zlog_default->default_lvl); + return; + } + + if (strcmp(option, "syslog") == 0) { + zlog_set_level(ZLOG_DEST_SYSLOG, zlog_default->default_lvl); + return; + } + + token = strstr(option, ":"); + token++; + + set_log_file(NULL, token, zlog_default->default_lvl); +} + DEFUN (config_log_file, config_log_file_cmd, "log file FILENAME []", -- cgit v1.2.3