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

@ -116,7 +116,7 @@ netconf_add_request_attr(cxobj *xrpc,
if (xml_find_type(xrep, NULL, xml_name(xa), CX_ATTR) != NULL)
continue; /* Skip already present (dont overwrite) */
/* Filter all clixon-lib attributes and namespace declaration
* to acvoid leaking internal attributes to external NETCONF
* to avoid leaking internal attributes to external NETCONF
* note this is only done on top-level.
*/
if (xml_prefix(xa) && strcmp(xml_prefix(xa), CLIXON_LIB_PREFIX) == 0)
@ -687,6 +687,7 @@ main(int argc,
int config_dump = 0;
enum format_enum config_dump_format = FORMAT_XML;
int print_version = 0;
int32_t d;
/* Create handle */
if ((h = clixon_handle_init()) == NULL)
@ -703,7 +704,7 @@ main(int argc,
}
if (clicon_username_set(h, pw->pw_name) < 0)
goto done;
while ((c = getopt(argc, argv, NETCONF_OPTS)) != -1)
while ((c = getopt(argc, argv, NETCONF_OPTS)) != -1) {
switch (c) {
case 'h' : /* help */
usage(h, argv[0]);
@ -712,16 +713,14 @@ 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 */
int d = 0;
case 'D' : /* debug */
/* Try first symbolic, then numeric match */
if ((d = clixon_debug_str2key(optarg)) < 0 &&
sscanf(optarg, "%d", &d) != 1){
sscanf(optarg, "%u", &d) != 1){
usage(h, argv[0]);
}
dbg |= d;
break;
}
case 'f': /* override config file */
if (!strlen(optarg))
usage(h, argv[0]);
@ -733,14 +732,22 @@ 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;
int32_t d;
d = 0;
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;
}
}
/*
* Logs, error and debug to stderr or syslog, set debug level
@ -833,6 +840,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);