]> git.puffer.fish Git - matthieu/frr.git/commitdiff
lib: Add new cli to specify where to output logs on startup
authorDonald Sharp <sharpd@cumulusnetworks.com>
Fri, 15 Jun 2018 17:38:46 +0000 (13:38 -0400)
committerDonald Sharp <sharpd@cumulusnetworks.com>
Tue, 19 Jun 2018 12:43:59 +0000 (08:43 -0400)
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>
lib/command.c
lib/command.h
lib/libfrr.c
lib/libfrr.h

index a8e61c6bb4f1a8784ea2a441be104b1760c6deb9..32b052c36cabea879df82aa993a98c69252017c2 100644 (file)
@@ -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>]",
index 9bf482f41b6054c902adce326dd8839140a374fe..9ccd13c73ba4f4d7fd975909252f931d5c4876a5 100644 (file)
@@ -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 */
index 4f3b8c66d660a4bb9e1164afc20db16f2cc61277..929268832773b36b1ce870853e03803266596f06 100644 (file)
@@ -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
index 1c744ee1b90319c43d374a96521f537d2ade46c2..ecef8c616eb9d0777726cb357b0b799bc3e9ed09 100644 (file)
@@ -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);