Logging fixes

* Fixed: [Error message seen twice in some cases](https://github.com/clicon/clixon/issues/325)
* Extended `-l` command-line option to all clixon commands with a `none` option, eg `-l n` directs logging to `dev/null`
This commit is contained in:
Olof hagsand 2022-04-30 11:28:56 +02:00
parent ef302f0c05
commit 5551d753ef
10 changed files with 17 additions and 9 deletions

View file

@ -428,7 +428,7 @@ usage(clicon_handle h,
"\t-p <dir>\tYang directory path (see CLICON_YANG_DIR)\n"
"\t-G \t\tPrint auo-cli CLI syntax generated from YANG\n"
"\t-L \t\tDebug print dynamic CLI syntax including completions and expansions\n"
"\t-l <s|e|o|f<file>> \tLog on (s)yslog, std(e)rr, std(o)ut or (f)ile (stderr is default)\n"
"\t-l <s|e|o|n|f<file>> \tLog on (s)yslog, std(e)rr, std(o)ut, (n)one or (f)ile (stderr is default)\n"
"\t-y <file>\tOverride yang spec file (dont include .yang suffix)\n"
"\t-c <file>\tSpecify cli spec file.\n"
"\t-U <user>\tOver-ride unix user with a pseudo user for NACM.\n"

View file

@ -509,12 +509,15 @@ cli_plugin_finish(clicon_handle h)
/*! Help function to print a meaningful error string.
* Sometimes the libraries specify an error string, if so print that.
* Otherwise just print 'command error'.
* But do not print it if error is already logged in eg clicon_err() using STDERR logging
* See eg https://github.com/clicon/clixon/issues/325
* @param[in] f File handler to write error to.
*/
int
cli_handler_err(FILE *f)
{
if (clicon_errno){
if (clicon_errno &&
(clicon_get_logflags() & CLICON_LOG_STDERR) == 0){
fprintf(f, "%s: %s", clicon_strerror(clicon_errno), clicon_err_reason);
if (clicon_suberrno)
fprintf(f, ": %s", strerror(clicon_suberrno));