C-API: All calls to clicon_log_xml() changed to new function `clicon_debug_xml()\
Debugging, moved many detailed debugs from level 1 to 2
This commit is contained in:
parent
3916fa919c
commit
bc6cc2b31f
22 changed files with 114 additions and 49 deletions
|
|
@ -372,6 +372,7 @@ clicon_debug_get(void)
|
|||
* 1 default level if passed -D
|
||||
* 2.. Higher debug levels
|
||||
* @param[in] format Message to print as argv.
|
||||
* @see clicon_debug_xml Specialization for XML tree
|
||||
*/
|
||||
int
|
||||
clicon_debug(int dbglevel,
|
||||
|
|
@ -383,7 +384,7 @@ clicon_debug(int dbglevel,
|
|||
int retval = -1;
|
||||
size_t trunc;
|
||||
|
||||
if (dbglevel > _clixon_debug) /* compare debug mask with global variable */
|
||||
if (dbglevel > clicon_debug_get()) /* compare debug level with global variable */
|
||||
return 0;
|
||||
/* first round: compute length of debug message */
|
||||
va_start(args, format);
|
||||
|
|
|
|||
|
|
@ -194,7 +194,7 @@ clicon_msg_decode(struct clicon_msg *msg,
|
|||
*id = ntohl(msg->op_id);
|
||||
/* body */
|
||||
xmlstr = msg->op_body;
|
||||
clicon_debug(1, "%s %s", __FUNCTION__, xmlstr);
|
||||
clicon_debug(2, "%s %s", __FUNCTION__, xmlstr);
|
||||
if ((ret = clixon_xml_parse_string(xmlstr, yspec?YB_RPC:YB_NONE, yspec, xml, xerr)) < 0)
|
||||
goto done;
|
||||
if (ret == 0)
|
||||
|
|
|
|||
|
|
@ -1401,8 +1401,7 @@ xml_purge(cxobj *xc)
|
|||
* @param[in] i Number of xml child node (to remove)
|
||||
* @retval 0 OK
|
||||
* @retval -1
|
||||
* @note you should not remove xchild in loop (unless yoy keep track of xprev)
|
||||
*
|
||||
* @note you should not remove xchild in loop (unless you keep track of xprev)
|
||||
* @see xml_rootchild
|
||||
* @see xml_rm Remove the node itself from parent
|
||||
*/
|
||||
|
|
@ -2368,11 +2367,14 @@ xml_add_attr(cxobj *xn,
|
|||
return retval;
|
||||
}
|
||||
|
||||
/*! Specialization of clicon_debug with xml tree
|
||||
/*! Specialization of clicon_log with xml tree
|
||||
*
|
||||
* @param[in] dbglevel
|
||||
* @param[in] level log level, eg LOG_DEBUG,LOG_INFO,...,LOG_EMERG.
|
||||
* @param[in] x XML tree that is logged without prettyprint
|
||||
* @param[in] format Message to print as argv.
|
||||
*/
|
||||
* @see clicon_debug_xml which uses debug setting instead of direct syslog
|
||||
*/
|
||||
int
|
||||
clicon_log_xml(int level,
|
||||
cxobj *x,
|
||||
|
|
@ -2428,6 +2430,71 @@ clicon_log_xml(int level,
|
|||
return retval;
|
||||
}
|
||||
|
||||
/*! Specialization of clicon_debug with xml tree
|
||||
*
|
||||
* @param[in] dbglevel
|
||||
* @param[in] x XML tree that is logged without prettyprint
|
||||
* @param[in] format Message to print as argv.
|
||||
* @see clicon_log_xml For syslog
|
||||
* @see clicon_debug base function
|
||||
*/
|
||||
int
|
||||
clicon_debug_xml(int dbglevel,
|
||||
cxobj *x,
|
||||
const char *format, ...)
|
||||
{
|
||||
va_list args;
|
||||
size_t len;
|
||||
char *msg = NULL;
|
||||
cbuf *cb = NULL;
|
||||
int retval = -1;
|
||||
size_t trunc;
|
||||
|
||||
if (dbglevel > clicon_debug_get()) /* compare debug level with global variable */
|
||||
return 0;
|
||||
/* Print xml as cbuf */
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_XML, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
if (clixon_xml2cbuf(cb, x, 0, 0, -1, 0) < 0)
|
||||
goto done;
|
||||
/* first round: compute length of debug message */
|
||||
va_start(args, format);
|
||||
len = vsnprintf(NULL, 0, format, args);
|
||||
va_end(args);
|
||||
|
||||
/* Truncate long debug strings */
|
||||
if ((trunc = clicon_log_string_limit_get()) && trunc < len)
|
||||
len = trunc;
|
||||
|
||||
/* allocate a message string exactly fitting the message length */
|
||||
if ((msg = malloc(len+1)) == NULL){
|
||||
fprintf(stderr, "malloc: %s\n", strerror(errno)); /* dont use clicon_err here due to recursion */
|
||||
goto done;
|
||||
}
|
||||
|
||||
/* second round: compute write message from format and args */
|
||||
va_start(args, format);
|
||||
if (vsnprintf(msg, len+1, format, args) < 0){
|
||||
va_end(args);
|
||||
fprintf(stderr, "vsnprintf: %s\n", strerror(errno)); /* dont use clicon_err here due to recursion */
|
||||
goto done;
|
||||
}
|
||||
va_end(args);
|
||||
|
||||
/* Actually log it */
|
||||
clicon_debug(dbglevel, "%s: %s", msg, cbuf_get(cb));
|
||||
|
||||
retval = 0;
|
||||
done:
|
||||
if (cb)
|
||||
cbuf_free(cb);
|
||||
if (msg)
|
||||
free(msg);
|
||||
return retval;
|
||||
}
|
||||
|
||||
#ifdef XML_EXPLICIT_INDEX
|
||||
/*
|
||||
*
|
||||
|
|
|
|||
|
|
@ -575,7 +575,7 @@ xml_tree_prune_flagged(cxobj *xt,
|
|||
* @param[in] mask Which flags to test for
|
||||
* The function removes all branches that does pass test
|
||||
* @code
|
||||
* xml_tree_prune_flaggs(xt, XML_FLAG_MARK, XML_FLAG_MARK|XML_FLAG_DEFAULT);
|
||||
* xml_tree_prune_flags(xt, XML_FLAG_MARK, XML_FLAG_MARK|XML_FLAG_DEFAULT);
|
||||
* @endcode
|
||||
*/
|
||||
int
|
||||
|
|
|
|||
|
|
@ -531,6 +531,7 @@ xpath_parse(const char *xpath,
|
|||
clixon_xpath_yacc xpy = {0,};
|
||||
cbuf *cb = NULL;
|
||||
|
||||
clicon_debug(2, "%s", __FUNCTION__);
|
||||
if (xpath == NULL){
|
||||
clicon_err(OE_XML, EINVAL, "XPath is NULL");
|
||||
goto done;
|
||||
|
|
@ -542,7 +543,6 @@ xpath_parse(const char *xpath,
|
|||
goto done;
|
||||
if (xpath_parse_init(&xpy) < 0)
|
||||
goto done;
|
||||
clicon_debug(2,"%s",__FUNCTION__);
|
||||
if (clixon_xpath_parseparse(&xpy) != 0) { /* yacc returns 1 on error */
|
||||
clicon_log(LOG_NOTICE, "XPATH error: on line %d", xpy.xpy_linenum);
|
||||
if (clicon_errno == 0)
|
||||
|
|
@ -602,6 +602,7 @@ xpath_vec_ctx(cxobj *xcur,
|
|||
xpath_tree *xptree = NULL;
|
||||
xp_ctx xc = {0,};
|
||||
|
||||
clicon_debug(2, "%s", __FUNCTION__);
|
||||
if (xpath_parse(xpath, &xptree) < 0)
|
||||
goto done;
|
||||
xc.xc_type = XT_NODESET;
|
||||
|
|
@ -1081,6 +1082,7 @@ xpath2canonical(const char *xpath0,
|
|||
cbuf *xcb = NULL;
|
||||
int ret;
|
||||
|
||||
clicon_debug(2, "%s", __FUNCTION__);
|
||||
/* Parse input xpath into an xpath-tree */
|
||||
if (xpath_parse(xpath0, &xpt) < 0)
|
||||
goto done;
|
||||
|
|
|
|||
|
|
@ -1128,8 +1128,7 @@ xp_eval(xp_ctx *xc,
|
|||
xp_ctx *xr2 = NULL;
|
||||
int use_xr0 = 0; /* In 2nd child use transitively result of 1st child */
|
||||
|
||||
if (clicon_debug_get() > 1)
|
||||
ctx_print(stderr, xc, xpath_tree_int2str(xs->xs_type));
|
||||
// ctx_print(stderr, xc, xpath_tree_int2str(xs->xs_type));
|
||||
/* Pre-actions before check first child c0
|
||||
*/
|
||||
switch (xs->xs_type){
|
||||
|
|
@ -1368,8 +1367,7 @@ xp_eval(xp_ctx *xc,
|
|||
xr0 = NULL;
|
||||
}
|
||||
ok:
|
||||
if (clicon_debug_get() > 1)
|
||||
ctx_print(stderr, *xrp, xpath_tree_int2str(xs->xs_type));
|
||||
// ctx_print(stderr, *xrp, xpath_tree_int2str(xs->xs_type));
|
||||
retval = 0;
|
||||
done:
|
||||
if (xr2)
|
||||
|
|
|
|||
|
|
@ -466,6 +466,7 @@ yang_path_arg(yang_stmt *ys,
|
|||
xp_yang_ctx *xyr = NULL;
|
||||
xp_yang_ctx *xy = NULL;
|
||||
|
||||
clicon_debug(2, "%s", __FUNCTION__);
|
||||
if (path_arg == NULL){
|
||||
clicon_err(OE_XML, EINVAL, "path-arg is NULL");
|
||||
goto done;
|
||||
|
|
|
|||
|
|
@ -2909,7 +2909,7 @@ yang_features(clicon_handle h,
|
|||
ret = 0;
|
||||
if (yang_subparse(yang_argument_get(ys), ys, YA_IF_FEATURE, mainfile, 1, &ret) < 0)
|
||||
goto done;
|
||||
clicon_debug(1, "%s %s %d", __FUNCTION__, yang_argument_get(ys), ret);
|
||||
clicon_debug(2, "%s %s %d", __FUNCTION__, yang_argument_get(ys), ret);
|
||||
if (ret == 0)
|
||||
goto disabled;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -120,7 +120,7 @@ yang_schema_nodeid_subparse(char *str,
|
|||
int retval = -1;
|
||||
clixon_yang_schemanode_yacc ife = {0,};
|
||||
|
||||
clicon_debug(2, "%s %s", __FUNCTION__, str);
|
||||
clicon_debug(3, "%s %s", __FUNCTION__, str);
|
||||
ife.if_parse_string = str;
|
||||
ife.if_linenum = linenum;
|
||||
ife.if_mainfile = mainfile;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue