Skip to content

Commit

Permalink
Replaced clixon_get_logflags() with clixon_logflags_get()
Browse files Browse the repository at this point in the history
Added `clixon_logflags_set()`
  • Loading branch information
olofhagsand committed Aug 16, 2024
1 parent 39fb149 commit 1709537
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 18 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)`
Expand Down
2 changes: 1 addition & 1 deletion apps/cli/cli_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions apps/cli/cli_plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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;
Expand Down
28 changes: 17 additions & 11 deletions lib/clixon/clixon_log.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_ */
19 changes: 15 additions & 4 deletions lib/src/clixon_log.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 1709537

Please sign in to comment.