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:
Olof hagsand 2024-02-02 11:47:01 +01:00
parent 86f251f343
commit 4e3bd6fbdd
39 changed files with 564 additions and 416 deletions

View file

@ -46,27 +46,38 @@
* Constants
*/
/* Debug flags are seperated into subject areas and detail
* @see dbgmap Symbolic mapping (if you change here you may need to change dbgmap)
*/
/* Detail level */
#define CLIXON_DBG_ALWAYS 0x000000 /* Unconditionally logged */
#define CLIXON_DBG_DETAIL 0x010000 /* Details: traces, parse trees, etc */
#define CLIXON_DBG_DETAIL2 0x020000 /* Extra details */
#define CLIXON_DBG_DETAIL3 0x030000 /* Probably more detail than you want */
#define CLIXON_DBG_DMASK 0x030000 /* Detail mask */
#define CLIXON_DBG_DSHIFT 16
#define CLIXON_DBG_ALWAYS 0x00000000 /* Unconditionally logged */
#define CLIXON_DBG_DETAIL 0x01000000 /* Details: traces, parse trees, etc */
#define CLIXON_DBG_DETAIL2 0x02000000 /* Extra details */
#define CLIXON_DBG_DETAIL3 0x03000000 /* Probably more detail than you want */
#define CLIXON_DBG_DMASK 0x03000000 /* Detail mask */
#define CLIXON_DBG_DSHIFT 24
/* Subject area */
#define CLIXON_DBG_DEFAULT 0x000001 /* Default logs */
#define CLIXON_DBG_MSG 0x000002 /* In/out messages */
#define CLIXON_DBG_XML 0x000004 /* XML processing */
#define CLIXON_DBG_XPATH 0x000008 /* XPath processing */
#define CLIXON_DBG_YANG 0x000010 /* YANG processing */
#define CLIXON_DBG_CLIENT 0x000020 /* App-specific */
#define CLIXON_DBG_NACM 0x000040 /* NACM processing */
#define CLIXON_DBG_PROC 0x000080 /* Process handling */
#define CLIXON_DBG_DATASTORE 0x000100 /* Datastore management */
#define CLIXON_DBG_EVENT 0x000200 /* Event processing */
#define CLIXON_DBG_RPC 0x000400 /* RPC handling */
#define CLIXON_DBG_SMASK 0x00ffff /* Subject mask */
#define CLIXON_DBG_DEFAULT 0x00000001 /* Default logs */
#define CLIXON_DBG_MSG 0x00000002 /* In/out messages */
#define CLIXON_DBG_XML 0x00000004 /* XML processing */
#define CLIXON_DBG_XPATH 0x00000008 /* XPath processing */
#define CLIXON_DBG_YANG 0x00000010 /* YANG processing */
#define CLIXON_DBG_BACKEND 0x00000020 /* Backend-specific */
#define CLIXON_DBG_CLI 0x00000040 /* CLI frontend */
#define CLIXON_DBG_NETCONF 0x00000080 /* NETCONF frontend */
#define CLIXON_DBG_RESTCONF 0x00000100 /* RESTCONF frontend */
#define CLIXON_DBG_SNMP 0x00000200 /* SNMP frontend */
#define CLIXON_DBG_NACM 0x00000400 /* NACM processing */
#define CLIXON_DBG_PROC 0x00000800 /* Process handling */
#define CLIXON_DBG_DATASTORE 0x00001000 /* Datastore management */
#define CLIXON_DBG_EVENT 0x00002000 /* Event processing */
#define CLIXON_DBG_RPC 0x00004000 /* RPC handling */
#define CLIXON_DBG_STREAM 0x00008000 /* Notification streams */
#define CLIXON_DBG_APP 0x00010000 /* External application */
#define CLIXON_DBG_APP2 0x00020000 /* External application 2 */
#define CLIXON_DBG_APP3 0x00040000 /* External application 3 */
#define CLIXON_DBG_SMASK 0x0003ffff /* Subject mask */
/*
* Macros
@ -115,6 +126,9 @@
/*
* Prototypes
*/
char *clixon_debug_key2str(int keyword);
int clixon_debug_str2key(char *str);
int clixon_debug_key_dump(FILE *f);
int clixon_debug_init(clixon_handle h, int dbglevel);
int clixon_debug_get(void);
int clixon_debug_fn(clixon_handle h, const char *fn, const int line, int dbglevel, cxobj *x, const char *format, ...) __attribute__ ((format (printf, 6, 7)));

View file

@ -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;

View file

@ -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: