log debug

This commit is contained in:
Olof Hagsand 2016-07-18 16:14:16 +02:00
parent eaaf1b83e8
commit 8bf95cab31
5 changed files with 84 additions and 17 deletions

View file

@ -667,10 +667,17 @@ from_client_call(clicon_handle h,
goto done;
}
retval = send_msg_reply(s,CLICON_MSG_OK, (char *)reply_data, reply_data_len);
free(reply_data);
if ((retval = send_msg_reply(s, CLICON_MSG_OK, (char *)reply_data, reply_data_len)) < 0){
if (errno == ECONNRESET){ /* If cli/netconf dies during plugin downcall */
clicon_log(LOG_WARNING, "client downcall reset");
retval = 0;
}
else
goto done;
}
done:
if (reply_data)
free(reply_data);
return retval;
}

View file

@ -92,14 +92,16 @@ exit_candidate_db(clicon_handle h)
return 0;
}
/*
* cli_debug
* set debug level on stderr (not syslog).
#if 1 /* OBSOLETE */
/*! Set debug level
* The level is either what is specified in arg as int argument.
* _or_ if a 'level' variable is present in vars use that value instead.
* OBSOLETE
*/
int
cli_debug(clicon_handle h, cvec *vars, cg_var *arg)
cli_debug(clicon_handle h,
cvec *vars,
cg_var *arg)
{
cg_var *cv;
int level;
@ -115,7 +117,52 @@ cli_debug(clicon_handle h, cvec *vars, cg_var *arg)
done:
return 0;
}
#endif
/*! Set debug level on CLI client (not backend daemon)
* @param[in] h Clicon handle
* @param[in] vars If variable "level" exists, its integer value is used
* @param[in] arg Else use the integer value of argument
* @note The level is either what is specified in arg as int argument.
* _or_ if a 'level' variable is present in vars use that value instead.
*/
int
cli_debug_cli(clicon_handle h,
cvec *vars,
cg_var *arg)
{
cg_var *cv;
int level;
if ((cv = cvec_find_var(vars, "level")) == NULL)
cv = arg;
level = cv_int32_get(cv);
/* cli */
clicon_debug_init(level, NULL); /* 0: dont debug, 1:debug */
return 0;
}
/*! Set debug level on backend daemon (not CLI)
* @param[in] h Clicon handle
* @param[in] vars If variable "level" exists, its integer value is used
* @param[in] arg Else use the integer value of argument
* @note The level is either what is specified in arg as int argument.
* _or_ if a 'level' variable is present in vars use that value instead.
*/
int
cli_debug_backend(clicon_handle h,
cvec *vars,
cg_var *arg)
{
cg_var *cv;
int level;
if ((cv = cvec_find_var(vars, "level")) == NULL)
cv = arg;
level = cv_int32_get(cv);
/* config daemon */
return clicon_rpc_debug(h, level);
}
void
cli_signal_block(clicon_handle h)

View file

@ -61,7 +61,8 @@ int exit_candidate_db(clicon_handle h);
int cli_set (clicon_handle h, cvec *vars, cg_var *arg);
int cli_merge (clicon_handle h, cvec *vars, cg_var *arg);
int cli_del(clicon_handle h, cvec *vars, cg_var *argv);
int cli_debug(clicon_handle h, cvec *vars, cg_var *argv);
int cli_debug_cli(clicon_handle h, cvec *vars, cg_var *argv);
int cli_debug_backend(clicon_handle h, cvec *vars, cg_var *argv);
int cli_record(clicon_handle h, cvec *vars, cg_var *argv);
int isrecording(void);
int record_command(char *str);

View file

@ -138,10 +138,11 @@ slogtime(void)
}
/*! Make a logging call to syslog.
/*! Make a logging call to syslog (or stderr).
*
* This is the _only_ place the actual syslog (or stderr) logging is made in clicon,..
* See also clicon_log()
* @note yslog makes itw own filtering, but if log to stderr we do it here
* @see clicon_debug()
*
* @param[in] level log level, eg LOG_DEBUG,LOG_INFO,...,LOG_EMERG. Thisis OR:d with facility == LOG_USER
* @param[in] msg Message to print as argv.
@ -152,6 +153,11 @@ clicon_log_str(int level,
{
if (_logflags & CLICON_LOG_SYSLOG)
syslog(LOG_MAKEPRI(LOG_USER, level), "%s", msg);
/* syslog makes own filtering, we do it here:
* if normal (not debug) then filter loglevels >= debug
*/
if (debug == 0 && level >= LOG_DEBUG)
goto done;
if (_logflags & CLICON_LOG_STDERR){
flogtime(stderr);
fprintf(stderr, "%s\n", msg);
@ -184,6 +190,7 @@ clicon_log_str(int level,
}
cb--;
}
done:
return 0;
}

View file

@ -388,9 +388,14 @@ downcall(clicon_handle h, uint16_t op, uint16_t len, void *arg,
* unchunk_group(label) to deallocate
*/
int
clicon_rpc_call(clicon_handle h, uint16_t op, char *plugin, char *func,
void *param, uint16_t paramlen,
char **ret, uint16_t *retlen,
clicon_rpc_call(clicon_handle h,
uint16_t op,
char *plugin,
char *func,
void *param,
uint16_t paramlen,
char **ret,
uint16_t *retlen,
const void *label)
{
int retval = -1;