summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorDonald Sharp <sharpd@cumulusnetworks.com>2018-06-15 19:38:46 +0200
committerDonald Sharp <sharpd@cumulusnetworks.com>2018-06-19 14:43:59 +0200
commitf8507817cf19d621cefd1d0310925ad07ec4646e (patch)
tree3ea82f53181723fb6e4ff91a417f9bc73f019a3f /lib
parentvtysh: Fix 'no log syslog ..' to be correct (diff)
downloadfrr-f8507817cf19d621cefd1d0310925ad07ec4646e.tar.xz
frr-f8507817cf19d621cefd1d0310925ad07ec4646e.zip
lib: Add new cli to specify where to output logs on startup
When we are starting a daemon, allow the user to specify: --log <stdout|syslog|file:file_name> 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 <sharpd@cumulusnetworks.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/command.c23
-rw-r--r--lib/command.h1
-rw-r--r--lib/libfrr.c11
-rw-r--r--lib/libfrr.h1
4 files changed, 34 insertions, 2 deletions
diff --git a/lib/command.c b/lib/command.c
index a8e61c6bb..32b052c36 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 [<emergencies|alerts|critical|errors|warnings|notifications|informational|debugging>]",
diff --git a/lib/command.h b/lib/command.h
index 9bf482f41..9ccd13c73 100644
--- a/lib/command.h
+++ b/lib/command.h
@@ -479,4 +479,5 @@ extern void
cmd_variable_handler_register(const struct cmd_variable_handler *cvh);
extern char *cmd_variable_comp2str(vector comps, unsigned short cols);
+extern void command_setup_early_logging(const char *option);
#endif /* _ZEBRA_COMMAND_H */
diff --git a/lib/libfrr.c b/lib/libfrr.c
index 4f3b8c66d..929268832 100644
--- a/lib/libfrr.c
+++ b/lib/libfrr.c
@@ -78,6 +78,7 @@ static void opt_extend(const struct optspec *os)
#define OPTION_VTYSOCK 1000
#define OPTION_MODULEDIR 1002
+#define OPTION_LOG 1003
static const struct option lo_always[] = {
{"help", no_argument, NULL, 'h'},
@@ -86,6 +87,7 @@ static const struct option lo_always[] = {
{"module", no_argument, NULL, 'M'},
{"vty_socket", required_argument, NULL, OPTION_VTYSOCK},
{"moduledir", required_argument, NULL, OPTION_MODULEDIR},
+ {"log", required_argument, NULL, OPTION_LOG},
{NULL}};
static const struct optspec os_always = {
"hvdM:",
@@ -94,7 +96,8 @@ static const struct optspec os_always = {
" -d, --daemon Runs in daemon mode\n"
" -M, --module Load specified module\n"
" --vty_socket Override vty socket path\n"
- " --moduledir Override modules directory\n",
+ " --moduledir Override modules directory\n"
+ " --log Set Logging to stdout, syslog, or file:<name>\n",
lo_always};
@@ -444,6 +447,9 @@ static int frr_opt(int opt)
return 1;
di->privs->group = optarg;
break;
+ case OPTION_LOG:
+ di->early_logging = optarg;
+ break;
default:
return 1;
}
@@ -543,6 +549,9 @@ struct thread_master *frr_init(void)
openzlog(di->progname, di->logname, di->instance,
LOG_CONS | LOG_NDELAY | LOG_PID, LOG_DAEMON);
+
+ if (di->early_logging)
+ command_setup_early_logging(di->early_logging);
#if defined(HAVE_CUMULUS)
zlog_set_level(ZLOG_DEST_SYSLOG, zlog_default->default_lvl);
#endif
diff --git a/lib/libfrr.h b/lib/libfrr.h
index 1c744ee1b..ecef8c616 100644
--- a/lib/libfrr.h
+++ b/lib/libfrr.h
@@ -58,6 +58,7 @@ struct frr_daemon_info {
const char *vty_path;
const char *module_path;
const char *pathspace;
+ const char *early_logging;
const char *proghelp;
void (*printhelp)(FILE *target);