mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-08-13 16:26:10 +00:00
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>
This commit is contained in:
parent
1f14323649
commit
f8507817cf
@ -2429,7 +2429,8 @@ static int set_log_file(struct vty *vty, const char *fname, int loglevel)
|
|||||||
XFREE(MTYPE_TMP, p);
|
XFREE(MTYPE_TMP, p);
|
||||||
|
|
||||||
if (!ret) {
|
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;
|
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;
|
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,
|
DEFUN (config_log_file,
|
||||||
config_log_file_cmd,
|
config_log_file_cmd,
|
||||||
"log file FILENAME [<emergencies|alerts|critical|errors|warnings|notifications|informational|debugging>]",
|
"log file FILENAME [<emergencies|alerts|critical|errors|warnings|notifications|informational|debugging>]",
|
||||||
|
@ -479,4 +479,5 @@ extern void
|
|||||||
cmd_variable_handler_register(const struct cmd_variable_handler *cvh);
|
cmd_variable_handler_register(const struct cmd_variable_handler *cvh);
|
||||||
extern char *cmd_variable_comp2str(vector comps, unsigned short cols);
|
extern char *cmd_variable_comp2str(vector comps, unsigned short cols);
|
||||||
|
|
||||||
|
extern void command_setup_early_logging(const char *option);
|
||||||
#endif /* _ZEBRA_COMMAND_H */
|
#endif /* _ZEBRA_COMMAND_H */
|
||||||
|
11
lib/libfrr.c
11
lib/libfrr.c
@ -78,6 +78,7 @@ static void opt_extend(const struct optspec *os)
|
|||||||
|
|
||||||
#define OPTION_VTYSOCK 1000
|
#define OPTION_VTYSOCK 1000
|
||||||
#define OPTION_MODULEDIR 1002
|
#define OPTION_MODULEDIR 1002
|
||||||
|
#define OPTION_LOG 1003
|
||||||
|
|
||||||
static const struct option lo_always[] = {
|
static const struct option lo_always[] = {
|
||||||
{"help", no_argument, NULL, 'h'},
|
{"help", no_argument, NULL, 'h'},
|
||||||
@ -86,6 +87,7 @@ static const struct option lo_always[] = {
|
|||||||
{"module", no_argument, NULL, 'M'},
|
{"module", no_argument, NULL, 'M'},
|
||||||
{"vty_socket", required_argument, NULL, OPTION_VTYSOCK},
|
{"vty_socket", required_argument, NULL, OPTION_VTYSOCK},
|
||||||
{"moduledir", required_argument, NULL, OPTION_MODULEDIR},
|
{"moduledir", required_argument, NULL, OPTION_MODULEDIR},
|
||||||
|
{"log", required_argument, NULL, OPTION_LOG},
|
||||||
{NULL}};
|
{NULL}};
|
||||||
static const struct optspec os_always = {
|
static const struct optspec os_always = {
|
||||||
"hvdM:",
|
"hvdM:",
|
||||||
@ -94,7 +96,8 @@ static const struct optspec os_always = {
|
|||||||
" -d, --daemon Runs in daemon mode\n"
|
" -d, --daemon Runs in daemon mode\n"
|
||||||
" -M, --module Load specified module\n"
|
" -M, --module Load specified module\n"
|
||||||
" --vty_socket Override vty socket path\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};
|
lo_always};
|
||||||
|
|
||||||
|
|
||||||
@ -444,6 +447,9 @@ static int frr_opt(int opt)
|
|||||||
return 1;
|
return 1;
|
||||||
di->privs->group = optarg;
|
di->privs->group = optarg;
|
||||||
break;
|
break;
|
||||||
|
case OPTION_LOG:
|
||||||
|
di->early_logging = optarg;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -543,6 +549,9 @@ struct thread_master *frr_init(void)
|
|||||||
|
|
||||||
openzlog(di->progname, di->logname, di->instance,
|
openzlog(di->progname, di->logname, di->instance,
|
||||||
LOG_CONS | LOG_NDELAY | LOG_PID, LOG_DAEMON);
|
LOG_CONS | LOG_NDELAY | LOG_PID, LOG_DAEMON);
|
||||||
|
|
||||||
|
if (di->early_logging)
|
||||||
|
command_setup_early_logging(di->early_logging);
|
||||||
#if defined(HAVE_CUMULUS)
|
#if defined(HAVE_CUMULUS)
|
||||||
zlog_set_level(ZLOG_DEST_SYSLOG, zlog_default->default_lvl);
|
zlog_set_level(ZLOG_DEST_SYSLOG, zlog_default->default_lvl);
|
||||||
#endif
|
#endif
|
||||||
|
@ -58,6 +58,7 @@ struct frr_daemon_info {
|
|||||||
const char *vty_path;
|
const char *vty_path;
|
||||||
const char *module_path;
|
const char *module_path;
|
||||||
const char *pathspace;
|
const char *pathspace;
|
||||||
|
const char *early_logging;
|
||||||
|
|
||||||
const char *proghelp;
|
const char *proghelp;
|
||||||
void (*printhelp)(FILE *target);
|
void (*printhelp)(FILE *target);
|
||||||
|
Loading…
Reference in New Issue
Block a user