From 170953770160748cc7c21677fe3af5c2111015c5 Mon Sep 17 00:00:00 2001 From: Olof hagsand Date: Fri, 16 Aug 2024 10:31:52 +0200 Subject: [PATCH] Replaced `clixon_get_logflags()` with `clixon_logflags_get()` Added `clixon_logflags_set()` --- CHANGELOG.md | 1 + apps/cli/cli_main.c | 2 +- apps/cli/cli_plugin.c | 4 ++-- lib/clixon/clixon_log.h | 28 +++++++++++++++++----------- lib/src/clixon_log.c | 19 +++++++++++++++---- 5 files changed, 36 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ec425c256..17133714e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -41,6 +41,7 @@ Users may have to change how they access the system Developers may need to change their code +* Replaced `clixon_get_logflags()` with `clixon_logflags_get()` * New `yn_iter()` yang iterator replaces `yn_each()` * Use an integer iterator instead of yang object * Replace `y1 = NULL; y1 = yn_each(y0, y1)` with `int inext = 0; yn_iter(y0, &inext)` diff --git a/apps/cli/cli_main.c b/apps/cli/cli_main.c index c9e36d8fc..ff88759b8 100644 --- a/apps/cli/cli_main.c +++ b/apps/cli/cli_main.c @@ -977,7 +977,7 @@ main(int argc, free(restarg); /* Dont log terminate on stderr or stdout */ clixon_log_init(h, __PROGRAM__, LOG_INFO, - clixon_get_logflags() & ~(CLIXON_LOG_STDERR|CLIXON_LOG_STDOUT)); + clixon_logflags_get() & ~(CLIXON_LOG_STDERR|CLIXON_LOG_STDOUT)); clixon_log(h, LOG_NOTICE, "%s: %u Terminated", __PROGRAM__, getpid()); if (h) cli_terminate(h); diff --git a/apps/cli/cli_plugin.c b/apps/cli/cli_plugin.c index 316045bc2..1dd732252 100644 --- a/apps/cli/cli_plugin.c +++ b/apps/cli/cli_plugin.c @@ -487,7 +487,7 @@ cli_handler_err(FILE *f) { if (clixon_err_category()){ /* Check if error is already logged on stderr */ - if ((clixon_get_logflags() & CLIXON_LOG_STDERR) == 0){ + if ((clixon_logflags_get() & CLIXON_LOG_STDERR) == 0){ if (clixon_err_category() != -1) fprintf(f, "%s: ", clixon_err_str()); fprintf(f, "%s", clixon_err_reason()); @@ -537,7 +537,7 @@ clicon_parse(clixon_handle h, pt_head *ph; ch = cli_cligen(h); - if (clixon_get_logflags()&CLIXON_LOG_STDOUT) + if (clixon_logflags_get()&CLIXON_LOG_STDOUT) f = stdout; else f = stderr; diff --git a/lib/clixon/clixon_log.h b/lib/clixon/clixon_log.h index a831c97d8..b450a9e1a 100644 --- a/lib/clixon/clixon_log.h +++ b/lib/clixon/clixon_log.h @@ -68,19 +68,25 @@ enum clixon_log_type{ #define clixon_log(h, l, _fmt, args...) clixon_log_fn((h), 1, (l), NULL, _fmt , ##args) #define clixon_log_xml(h, l, x, _fmt, args...) clixon_log_fn((h), 1, (l), x, _fmt , ##args) +// COMPAT_7_1 +#define clixon_get_logflags() clixon_logflags_get() + /* * Prototypes */ -char *clixon_logdst_key2str(int keyword); -int clixon_logdst_str2key(char *str); -int clixon_log_init(clixon_handle h, char *ident, int upto, int flags); -int clixon_log_exit(void); -int clixon_log_opt(char c); -int clixon_log_file(char *filename); -int clixon_log_string_limit_set(size_t sz); -size_t clixon_log_string_limit_get(void); -int clixon_get_logflags(void); -int clixon_log_str(int level, char *msg); -int clixon_log_fn(clixon_handle h, int user, int level, cxobj *x, const char *format, ...) __attribute__ ((format (printf, 5, 6))); +char *clixon_logdst_key2str(int keyword); +int clixon_logdst_str2key(char *str); +int clixon_log_init(clixon_handle h, char *ident, int upto, uint16_t flags); +int clixon_log_exit(void); +int clixon_log_opt(char c); +int clixon_log_file(char *filename); +int clixon_log_string_limit_set(size_t sz); +size_t clixon_log_string_limit_get(void); +uint16_t clixon_logflags_get(void); +int clixon_logflags_set(uint16_t flags); +int clixon_log_str(int level, char *msg); +int clixon_log_fn(clixon_handle h, int user, int level, cxobj *x, const char *format, ...) __attribute__ ((format (printf, 5, 6))); + + #endif /* _CLIXON_LOG_H_ */ diff --git a/lib/src/clixon_log.c b/lib/src/clixon_log.c index 98956f118..92a0fdf10 100644 --- a/lib/src/clixon_log.c +++ b/lib/src/clixon_log.c @@ -80,7 +80,7 @@ static clixon_handle _log_clixon_h = NULL; /* Bitmask whether to log to syslog or stderr: CLIXON_LOG_STDERR | CLIXON_LOG_SYSLOG */ -static int _log_flags = 0x0; +static uint16_t _log_flags = 0x0; /* Set to open file to write debug messages directly to file */ static FILE *_log_file = NULL; @@ -148,7 +148,7 @@ int clixon_log_init(clixon_handle h, char *ident, int upto, - int flags) + uint16_t flags) { _log_clixon_h = h; _log_flags = flags; @@ -222,12 +222,23 @@ clixon_log_file(char *filename) return 0; } -int -clixon_get_logflags(void) +/*! Get log flags + */ +uint16_t +clixon_logflags_get(void) { return _log_flags; } +/*! Replace log flags + */ +int +clixon_logflags_set(uint16_t flags) +{ + _log_flags = flags; + return 0; +} + /*! Truncate log/debug string length */ int