mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-08-06 07:27:09 +00:00
lib: Add --log-level to daemons
Add the ability to specify the designated log level at startup. --log-level <emergencies|alerts|critical|errors|warnings|notifications|informational|debugging> Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
This commit is contained in:
parent
9685abb492
commit
e9b4e74a78
@ -2446,21 +2446,31 @@ static int set_log_file(struct vty *vty, const char *fname, int loglevel)
|
||||
return CMD_SUCCESS;
|
||||
}
|
||||
|
||||
void command_setup_early_logging(const char *option)
|
||||
void command_setup_early_logging(const char *dest, const char *level)
|
||||
{
|
||||
char *token;
|
||||
|
||||
if (strcmp(option, "stdout") == 0) {
|
||||
if (level) {
|
||||
int nlevel = level_match(level);
|
||||
|
||||
if (nlevel != ZLOG_DISABLED)
|
||||
zlog_default->default_lvl = nlevel;
|
||||
}
|
||||
|
||||
if (!dest)
|
||||
return;
|
||||
|
||||
if (strcmp(dest, "stdout") == 0) {
|
||||
zlog_set_level(ZLOG_DEST_STDOUT, zlog_default->default_lvl);
|
||||
return;
|
||||
}
|
||||
|
||||
if (strcmp(option, "syslog") == 0) {
|
||||
if (strcmp(dest, "syslog") == 0) {
|
||||
zlog_set_level(ZLOG_DEST_SYSLOG, zlog_default->default_lvl);
|
||||
return;
|
||||
}
|
||||
|
||||
token = strstr(option, ":");
|
||||
token = strstr(dest, ":");
|
||||
token++;
|
||||
|
||||
set_log_file(NULL, token, zlog_default->default_lvl);
|
||||
|
@ -479,5 +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);
|
||||
extern void command_setup_early_logging(const char *dest, const char *level);
|
||||
#endif /* _ZEBRA_COMMAND_H */
|
||||
|
13
lib/libfrr.c
13
lib/libfrr.c
@ -78,7 +78,8 @@ static void opt_extend(const struct optspec *os)
|
||||
|
||||
#define OPTION_VTYSOCK 1000
|
||||
#define OPTION_MODULEDIR 1002
|
||||
#define OPTION_LOG 1003
|
||||
#define OPTION_LOG 1003
|
||||
#define OPTION_LOGLEVEL 1004
|
||||
|
||||
static const struct option lo_always[] = {
|
||||
{"help", no_argument, NULL, 'h'},
|
||||
@ -88,6 +89,7 @@ static const struct option lo_always[] = {
|
||||
{"vty_socket", required_argument, NULL, OPTION_VTYSOCK},
|
||||
{"moduledir", required_argument, NULL, OPTION_MODULEDIR},
|
||||
{"log", required_argument, NULL, OPTION_LOG},
|
||||
{"log-level", required_argument, NULL, OPTION_LOGLEVEL},
|
||||
{NULL}};
|
||||
static const struct optspec os_always = {
|
||||
"hvdM:",
|
||||
@ -97,7 +99,8 @@ static const struct optspec os_always = {
|
||||
" -M, --module Load specified module\n"
|
||||
" --vty_socket Override vty socket path\n"
|
||||
" --moduledir Override modules directory\n"
|
||||
" --log Set Logging to stdout, syslog, or file:<name>\n",
|
||||
" --log Set Logging to stdout, syslog, or file:<name>\n"
|
||||
" --log-level Set Logging Level to use, debug, info, warn, etc\n",
|
||||
lo_always};
|
||||
|
||||
|
||||
@ -450,6 +453,9 @@ static int frr_opt(int opt)
|
||||
case OPTION_LOG:
|
||||
di->early_logging = optarg;
|
||||
break;
|
||||
case OPTION_LOGLEVEL:
|
||||
di->early_loglevel = optarg;
|
||||
break;
|
||||
default:
|
||||
return 1;
|
||||
}
|
||||
@ -550,8 +556,7 @@ 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);
|
||||
command_setup_early_logging(di->early_logging, di->early_loglevel);
|
||||
|
||||
if (!frr_zclient_addr(&zclient_addr, &zclient_addr_len,
|
||||
frr_zclientpath)) {
|
||||
|
@ -59,6 +59,7 @@ struct frr_daemon_info {
|
||||
const char *module_path;
|
||||
const char *pathspace;
|
||||
const char *early_logging;
|
||||
const char *early_loglevel;
|
||||
|
||||
const char *proghelp;
|
||||
void (*printhelp)(FILE *target);
|
||||
|
Loading…
Reference in New Issue
Block a user