Added CLICON_LOG_DESTINATION and CLICON_LOG_FILE for al applications

This commit is contained in:
Olof hagsand 2024-06-19 12:28:39 +02:00
parent 26062d7003
commit 0234ed94bc
22 changed files with 498 additions and 163 deletions

View file

@ -329,6 +329,7 @@ main(int argc,
enum format_enum config_dump_format = FORMAT_XML;
int print_version = 0;
int stream_timeout = 0;
int32_t d;
/* Create handle */
if ((h = restconf_handle_init()) == NULL)
@ -351,7 +352,6 @@ main(int argc,
print_version++; /* plugins may also print versions w ca-version callback */
break;
case 'D' : { /* debug */
int d = 0;
/* Try first symbolic, then numeric match */
if ((d = clixon_debug_str2key(optarg)) < 0 &&
sscanf(optarg, "%d", &d) != 1){
@ -371,12 +371,17 @@ main(int argc,
clicon_option_str_set(h, "CLICON_CONFIGDIR", optarg);
break;
case 'l': /* Log destination: s|e|o */
if ((logdst = clixon_log_opt(optarg[0])) < 0)
usage(h, argv[0]);
if (logdst == CLIXON_LOG_FILE &&
strlen(optarg)>1 &&
clixon_log_file(optarg+1) < 0)
goto done;
if ((d = clixon_logdst_str2key(optarg)) < 0){
if (optarg[0] == 'f'){ /* Check for special -lf<file> syntax */
d = CLIXON_LOG_FILE;
if (strlen(optarg) > 1 &&
clixon_log_file(optarg+1) < 0)
goto done;
}
else
usage(h, argv[0]);
}
logdst = d;
break;
} /* switch getopt */
@ -466,6 +471,9 @@ main(int argc,
argc -= optind;
argv += optind;
/* Read debug and log options from config file if not given by command-line */
if (clixon_options_main_helper(h, dbg, logdst, __PROGRAM__) < 0)
goto done;
/* Access the remaining argv/argc options (after --) w clicon-argv_get() */
clicon_argv_set(h, argv0, argc, argv);

View file

@ -1168,6 +1168,7 @@ main(int argc,
enum format_enum config_dump_format = FORMAT_XML;
int print_version = 0;
int stream_timeout = 0;
int32_t d;
/* Create handle */
if ((h = restconf_handle_init()) == NULL)
@ -1187,17 +1188,13 @@ main(int argc,
cligen_output(stdout, "Clixon version: %s\n", CLIXON_GITHASH);
print_version++; /* plugins may also print versions w ca-version callback */
break;
case 'D' : { /* debug. Note this overrides any setting in the config */
int d = 0;
case 'D' : /* debug. Note this overrides any setting in the config */
/* Try first symbolic, then numeric match */
if ((d = clixon_debug_str2key(optarg)) < 0 &&
sscanf(optarg, "%d", &d) != 1){
usage(h, argv[0]);
}
dbg |= d;
break;
}
break;
case 'f': /* override config file */
if (!strlen(optarg))
@ -1210,13 +1207,18 @@ main(int argc,
clicon_option_str_set(h, "CLICON_CONFIGDIR", optarg);
break;
case 'l': /* Log destination: s|e|o */
if ((logdst = clixon_log_opt(optarg[0])) < 0)
usage(h, argv0);
if (logdst == CLIXON_LOG_FILE &&
strlen(optarg)>1 &&
clixon_log_file(optarg+1) < 0)
goto done;
break;
if ((d = clixon_logdst_str2key(optarg)) < 0){
if (optarg[0] == 'f'){ /* Check for special -lf<file> syntax */
d = CLIXON_LOG_FILE;
if (strlen(optarg) > 1 &&
clixon_log_file(optarg+1) < 0)
goto done;
}
else
usage(h, argv[0]);
}
logdst = d;
break;
} /* switch getopt */
/*
@ -1324,6 +1326,10 @@ main(int argc,
argc -= optind;
argv += optind;
/* Read debug and log options from config file if not given by command-line */
if (clixon_options_main_helper(h, dbg, logdst, __PROGRAM__) < 0)
goto done;
/* Access the remaining argv/argc options (after --) w clicon-argv_get() */
clicon_argv_set(h, argv0, argc, argv);