Symbolic and combined debug names in cmd-line of all applications
New debug levels: BACKEND, CLI, NETCONF,RESTCONF, SNMP, STREAM
This commit is contained in:
parent
86f251f343
commit
4e3bd6fbdd
39 changed files with 564 additions and 416 deletions
|
|
@ -60,6 +60,7 @@
|
|||
/* clixon */
|
||||
#include "clixon_queue.h"
|
||||
#include "clixon_hash.h"
|
||||
#include "clixon_string.h"
|
||||
#include "clixon_handle.h"
|
||||
#include "clixon_yang.h"
|
||||
#include "clixon_xml.h"
|
||||
|
|
@ -78,11 +79,84 @@
|
|||
/* Cache handle since debug calls do not have handle parameter */
|
||||
static clixon_handle _debug_clixon_h = NULL;
|
||||
|
||||
/*! Mapping between Clixon debug symbolic names <--> bitfields
|
||||
*
|
||||
* Mapping between specific bitfields and symbolic names, note only perfect matches
|
||||
*/
|
||||
static const map_str2int dbgmap[] = {
|
||||
{"default", CLIXON_DBG_DEFAULT},
|
||||
{"msg", CLIXON_DBG_MSG},
|
||||
{"xml", CLIXON_DBG_XML},
|
||||
{"xpath", CLIXON_DBG_XPATH},
|
||||
{"yang", CLIXON_DBG_YANG},
|
||||
{"backend", CLIXON_DBG_BACKEND},
|
||||
{"cli", CLIXON_DBG_CLI},
|
||||
{"netconf", CLIXON_DBG_NETCONF},
|
||||
{"restconf", CLIXON_DBG_RESTCONF},
|
||||
{"snmp", CLIXON_DBG_SNMP},
|
||||
{"nacm", CLIXON_DBG_NACM},
|
||||
{"proc", CLIXON_DBG_PROC},
|
||||
{"datastore", CLIXON_DBG_DATASTORE},
|
||||
{"event", CLIXON_DBG_EVENT},
|
||||
{"rpc", CLIXON_DBG_RPC},
|
||||
{"stream", CLIXON_DBG_STREAM},
|
||||
{"app", CLIXON_DBG_APP},
|
||||
{"app2", CLIXON_DBG_APP2},
|
||||
{"app3", CLIXON_DBG_APP3},
|
||||
{"all", CLIXON_DBG_SMASK},
|
||||
{"always", CLIXON_DBG_ALWAYS},
|
||||
{"detail", CLIXON_DBG_DETAIL},
|
||||
{"detail2", CLIXON_DBG_DETAIL2},
|
||||
{"detail3", CLIXON_DBG_DETAIL3},
|
||||
{NULL, -1}
|
||||
};
|
||||
|
||||
/*! Map from clixon debug (specific) bitmask to string
|
||||
*
|
||||
* @param[in] int Bitfield, see CLIXON_DBG_DEFAULT and others
|
||||
* @retval str String representation of bitfield
|
||||
*/
|
||||
char *
|
||||
clixon_debug_key2str(int keyword)
|
||||
{
|
||||
return (char*)clicon_int2str(dbgmap, keyword);
|
||||
}
|
||||
|
||||
/*! Map from clixon debug symbolic string to bitfield
|
||||
*
|
||||
* @param[in] str String representation of Clixon debug bit
|
||||
* @retval int Bit representation of bitfield
|
||||
*/
|
||||
int
|
||||
clixon_debug_str2key(char *str)
|
||||
{
|
||||
return clicon_str2int(dbgmap, str);
|
||||
}
|
||||
|
||||
/*! Dump the symbolic bitfield names
|
||||
*
|
||||
* @param[in] f Output file
|
||||
*/
|
||||
int
|
||||
clixon_debug_key_dump(FILE *f)
|
||||
{
|
||||
const struct map_str2int *ms;
|
||||
|
||||
for (ms = &dbgmap[0]; ms->ms_str; ms++){
|
||||
if (ms != &dbgmap[0])
|
||||
fprintf(f, ", ");
|
||||
fprintf(f, "%s", ms->ms_str);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*! The global debug level. 0 means no debug
|
||||
*
|
||||
* @note There are pros and cons in having the debug state as a global variable. The
|
||||
* alternative to bind it to the clicon handle (h) was considered but it limits its
|
||||
* usefulness, since not all functions have h
|
||||
* usefulness, since not all functions have access to a handle.
|
||||
* A compromise solution is now in place where h can be provided in the function call, but
|
||||
* tolerates NULL, in which case a cached handle is used.
|
||||
*/
|
||||
static int _debug_level = 0;
|
||||
|
||||
|
|
|
|||
|
|
@ -267,7 +267,7 @@ stream_timer_setup(int fd,
|
|||
struct stream_replay *r;
|
||||
struct stream_replay *r1;
|
||||
|
||||
clixon_debug(CLIXON_DBG_DEFAULT | CLIXON_DBG_DETAIL, "");
|
||||
clixon_debug(CLIXON_DBG_STREAM, "");
|
||||
/* Go thru callbacks and see if any have timed out, if so remove them
|
||||
* Could also be done by a separate timer.
|
||||
*/
|
||||
|
|
@ -348,7 +348,7 @@ stream_ss_add(clixon_handle h,
|
|||
event_stream_t *es;
|
||||
struct stream_subscription *ss = NULL;
|
||||
|
||||
clixon_debug(CLIXON_DBG_DEFAULT, "");
|
||||
clixon_debug(CLIXON_DBG_STREAM, "");
|
||||
if ((es = stream_find(h, stream)) == NULL){
|
||||
clixon_err(OE_CFG, ENOENT, "Stream %s not found", stream);
|
||||
goto done;
|
||||
|
|
@ -395,7 +395,7 @@ stream_ss_rm(clixon_handle h,
|
|||
struct stream_subscription *ss,
|
||||
int force)
|
||||
{
|
||||
clixon_debug(CLIXON_DBG_DEFAULT, "");
|
||||
clixon_debug(CLIXON_DBG_STREAM, "");
|
||||
DELQ(ss, es->es_subscription, struct stream_subscription *);
|
||||
/* Remove from upper layers - close socket etc. */
|
||||
(*ss->ss_fn)(h, 1, NULL, ss->ss_arg);
|
||||
|
|
@ -406,7 +406,7 @@ stream_ss_rm(clixon_handle h,
|
|||
free(ss->ss_xpath);
|
||||
free(ss);
|
||||
}
|
||||
clixon_debug(CLIXON_DBG_DEFAULT, "retval: 0");
|
||||
clixon_debug(CLIXON_DBG_STREAM, "retval: 0");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -519,7 +519,7 @@ stream_notify1(clixon_handle h,
|
|||
int retval = -1;
|
||||
struct stream_subscription *ss;
|
||||
|
||||
clixon_debug(CLIXON_DBG_DEFAULT | CLIXON_DBG_DETAIL, "");
|
||||
clixon_debug(CLIXON_DBG_STREAM, "");
|
||||
/* Go thru all subscriptions and find matches */
|
||||
if ((ss = es->es_subscription) != NULL)
|
||||
do {
|
||||
|
|
@ -575,7 +575,7 @@ stream_notify(clixon_handle h,
|
|||
struct timeval tv;
|
||||
event_stream_t *es;
|
||||
|
||||
clixon_debug(CLIXON_DBG_DEFAULT | CLIXON_DBG_DETAIL, "");
|
||||
clixon_debug(CLIXON_DBG_STREAM, "");
|
||||
if ((es = stream_find(h, stream)) == NULL)
|
||||
goto ok;
|
||||
va_start(args, event);
|
||||
|
|
@ -652,7 +652,7 @@ stream_notify_xml(clixon_handle h,
|
|||
struct timeval tv;
|
||||
event_stream_t *es;
|
||||
|
||||
clixon_debug(CLIXON_DBG_DEFAULT | CLIXON_DBG_DETAIL, "");
|
||||
clixon_debug(CLIXON_DBG_STREAM, "");
|
||||
if ((es = stream_find(h, stream)) == NULL)
|
||||
goto ok;
|
||||
if ((yspec = clicon_dbspec_yang(h)) == NULL){
|
||||
|
|
@ -940,15 +940,15 @@ url_post(char *url,
|
|||
CURLcode errcode;
|
||||
|
||||
/* Try it with curl -X PUT -d '*/
|
||||
clixon_debug(CLIXON_DBG_DEFAULT, "curl -X POST -d '%s' %s",
|
||||
clixon_debug(CLIXON_DBG_STREAM, "curl -X POST -d '%s' %s",
|
||||
postfields, url);
|
||||
/* Set up curl for doing the communication with the controller */
|
||||
if ((curl = curl_easy_init()) == NULL) {
|
||||
clixon_debug(CLIXON_DBG_DEFAULT, "curl_easy_init");
|
||||
clixon_debug(CLIXON_DBG_STREAM, "curl_easy_init");
|
||||
goto done;
|
||||
}
|
||||
if ((err = malloc(CURL_ERROR_SIZE)) == NULL) {
|
||||
clixon_debug(CLIXON_DBG_DEFAULT, "malloc");
|
||||
clixon_debug(CLIXON_DBG_STREAM, "malloc");
|
||||
goto done;
|
||||
}
|
||||
curl_easy_setopt(curl, CURLOPT_URL, url);
|
||||
|
|
@ -962,7 +962,7 @@ url_post(char *url,
|
|||
if (clixon_debug_get())
|
||||
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
|
||||
if ((errcode = curl_easy_perform(curl)) != CURLE_OK){
|
||||
clixon_debug(CLIXON_DBG_DEFAULT, "curl: %s(%d)", err, errcode);
|
||||
clixon_debug(CLIXON_DBG_STREAM, "curl: %s(%d)", err, errcode);
|
||||
retval = 0;
|
||||
goto done;
|
||||
}
|
||||
|
|
@ -1005,7 +1005,7 @@ stream_publish_cb(clixon_handle h,
|
|||
char *result = NULL;
|
||||
char *stream = (char*)arg;
|
||||
|
||||
clixon_debug(CLIXON_DBG_DEFAULT, "");
|
||||
clixon_debug(CLIXON_DBG_STREAM, "");
|
||||
if (op != 0)
|
||||
goto ok;
|
||||
/* Create pub url */
|
||||
|
|
@ -1030,7 +1030,7 @@ stream_publish_cb(clixon_handle h,
|
|||
&result) < 0) /* result as xml */
|
||||
goto done;
|
||||
if (result)
|
||||
clixon_debug(CLIXON_DBG_DEFAULT, "%s", result);
|
||||
clixon_debug(CLIXON_DBG_STREAM, "%s", result);
|
||||
ok:
|
||||
retval = 0;
|
||||
done:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue