Allow more complex debugging like YANG with DETAIL
This commit is contained in:
parent
762c9fcbd8
commit
20b233e96f
4 changed files with 34 additions and 13 deletions
|
|
@ -46,11 +46,20 @@
|
|||
* Constants
|
||||
*/
|
||||
|
||||
/* Debug-level masks */
|
||||
#define CLIXON_DBG_DEFAULT 1 /* Default logs */
|
||||
#define CLIXON_DBG_MSG 2 /* In/out messages and datastore reads */
|
||||
#define CLIXON_DBG_DETAIL 4 /* Details: traces, parse trees, etc */
|
||||
#define CLIXON_DBG_EXTRA 8 /* Extra Detailed logs */
|
||||
/* Detail level */
|
||||
#define CLIXON_DBG_ALWAYS 0x0 /* Unconditionally logged */
|
||||
#define CLIXON_DBG_DETAIL 0x1 /* Details: traces, parse trees, etc */
|
||||
#define CLIXON_DBG_DETAIL2 0x2 /* Extra details */
|
||||
#define CLIXON_DBG_DETAIL3 0x3 /* Probably more detail than you want */
|
||||
#define CLIXON_DBG_DMASK 0x3 /* Detail mask */
|
||||
|
||||
/* Subject area */
|
||||
#define CLIXON_DBG_DEFAULT 0x04 /* Default logs */
|
||||
#define CLIXON_DBG_MSG 0x08 /* In/out messages and datastore reads */
|
||||
#define CLIXON_DBG_XML 0x10 /* XML processing */
|
||||
#define CLIXON_DBG_XPATH 0x20 /* XPath processing */
|
||||
#define CLIXON_DBG_YANG 0x40 /* YANG processing */
|
||||
#define CLIXON_DBG_SMASK ~0x03 /* Subject mask */
|
||||
|
||||
/*
|
||||
* Macros
|
||||
|
|
@ -65,4 +74,16 @@ int clixon_debug_init(clixon_handle h, int dbglevel);
|
|||
int clixon_debug_get(void);
|
||||
int clixon_debug_fn(clixon_handle h, int dbglevel, cxobj *x, const char *format, ...) __attribute__ ((format (printf, 4, 5)));
|
||||
|
||||
static inline int clixon_debug_isset(unsigned n)
|
||||
{
|
||||
unsigned level = clixon_debug_get();
|
||||
unsigned detail = (n & CLIXON_DBG_DMASK);
|
||||
unsigned subject = (n & CLIXON_DBG_SMASK);
|
||||
|
||||
/* not this subject */
|
||||
if ((level & subject) == 0)
|
||||
return 0;
|
||||
return ((level & CLIXON_DBG_DMASK) >= detail);
|
||||
}
|
||||
|
||||
#endif /* _CLIXON_DEBUG_H_ */
|
||||
|
|
|
|||
|
|
@ -146,7 +146,7 @@ clixon_debug_fn(clixon_handle h,
|
|||
cbuf *cb = NULL;
|
||||
|
||||
/* Mask debug level with global dbg variable */
|
||||
if ((dbglevel & clixon_debug_get()) == 0)
|
||||
if (!clixon_debug_isset(dbglevel))
|
||||
return 0;
|
||||
if (h == NULL) /* Accept NULL, use saved clixon handle */
|
||||
h = _debug_clixon_h;
|
||||
|
|
|
|||
|
|
@ -322,7 +322,7 @@ msg_hex(int dbglevel,
|
|||
cbuf *cb = NULL;
|
||||
int i;
|
||||
|
||||
if ((dbglevel & clixon_debug_get()) == 0) /* compare debug level with global variable */
|
||||
if (!clixon_debug_isset(dbglevel)) /* compare debug level with global variable */
|
||||
goto ok;
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clixon_err(OE_CFG, errno, "cbuf_new");
|
||||
|
|
@ -372,7 +372,7 @@ clicon_msg_send(int s,
|
|||
else{
|
||||
clixon_debug(CLIXON_DBG_MSG, "Send: %s", msg->op_body);
|
||||
}
|
||||
msg_hex(CLIXON_DBG_EXTRA, (char*)msg, ntohl(msg->op_len), __FUNCTION__);
|
||||
msg_hex(CLIXON_DBG_DETAIL2, (char*)msg, ntohl(msg->op_len), __FUNCTION__);
|
||||
if (atomicio((ssize_t (*)(int, void *, size_t))write,
|
||||
s, msg, ntohl(msg->op_len)) < 0){
|
||||
e = errno;
|
||||
|
|
@ -438,7 +438,7 @@ clicon_msg_rcv(int s,
|
|||
clixon_err(OE_CFG, errno, "atomicio");
|
||||
goto done;
|
||||
}
|
||||
msg_hex(CLIXON_DBG_EXTRA, (char*)&hdr, hlen, __FUNCTION__);
|
||||
msg_hex(CLIXON_DBG_DETAIL2, (char*)&hdr, hlen, __FUNCTION__);
|
||||
if (hlen == 0){
|
||||
*eof = 1;
|
||||
goto ok;
|
||||
|
|
@ -448,7 +448,7 @@ clicon_msg_rcv(int s,
|
|||
goto done;
|
||||
}
|
||||
mlen = ntohl(hdr.op_len);
|
||||
clixon_debug(CLIXON_DBG_EXTRA, "op-len:%u op-id:%u",
|
||||
clixon_debug(CLIXON_DBG_DETAIL2, "op-len:%u op-id:%u",
|
||||
mlen, ntohl(hdr.op_id));
|
||||
clixon_debug(CLIXON_DBG_DETAIL, "%s: rcv msg len=%d",
|
||||
__FUNCTION__, mlen);
|
||||
|
|
@ -467,7 +467,7 @@ clicon_msg_rcv(int s,
|
|||
goto done;
|
||||
}
|
||||
if (len2)
|
||||
msg_hex(CLIXON_DBG_EXTRA, (*msg)->op_body, len2, __FUNCTION__);
|
||||
msg_hex(CLIXON_DBG_DETAIL2, (*msg)->op_body, len2, __FUNCTION__);
|
||||
if (len2 != mlen - sizeof(hdr)){
|
||||
clixon_err(OE_PROTO, 0, "body too short");
|
||||
*eof = 1;
|
||||
|
|
|
|||
|
|
@ -386,7 +386,7 @@ xml_cmp(cxobj *x1,
|
|||
break;
|
||||
} /* switch */
|
||||
done:
|
||||
clixon_debug(CLIXON_DBG_EXTRA, "%s %s %s eq:%d nr: %d %d yi: %d %d", __FUNCTION__, xml_name(x1), xml_name(x2), equal, nr1, nr2, yi1, yi2);
|
||||
clixon_debug(CLIXON_DBG_DETAIL2, "%s %s %s eq:%d nr: %d %d yi: %d %d", __FUNCTION__, xml_name(x1), xml_name(x2), equal, nr1, nr2, yi1, yi2);
|
||||
return equal;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue