diff --git a/compel/include/log.h b/compel/include/log.h index 5423cb84f..1f0442b78 100644 --- a/compel/include/log.h +++ b/compel/include/log.h @@ -10,22 +10,23 @@ static inline int pr_quelled(unsigned int loglevel) { - return compel_log_get_loglevel() < loglevel && loglevel != LOG_MSG; + return compel_log_get_loglevel() < loglevel + && loglevel != COMPEL_LOG_MSG; } extern void compel_print_on_level(unsigned int loglevel, const char *format, ...); #define pr_msg(fmt, ...) \ - compel_print_on_level(LOG_MSG, \ + compel_print_on_level(COMPEL_LOG_MSG, \ fmt, ##__VA_ARGS__) #define pr_info(fmt, ...) \ - compel_print_on_level(LOG_INFO, \ + compel_print_on_level(COMPEL_LOG_INFO, \ LOG_PREFIX fmt, ##__VA_ARGS__) #define pr_err(fmt, ...) \ - compel_print_on_level(LOG_ERROR, \ + compel_print_on_level(COMPEL_LOG_ERROR, \ "Error (%s:%d): " LOG_PREFIX fmt, \ __FILE__, __LINE__, ##__VA_ARGS__) @@ -39,7 +40,7 @@ extern void compel_print_on_level(unsigned int loglevel, } while (0) #define pr_warn(fmt, ...) \ - compel_print_on_level(LOG_WARN, \ + compel_print_on_level(COMPEL_LOG_WARN, \ "Warn (%s:%d): " LOG_PREFIX fmt, \ __FILE__, __LINE__, ##__VA_ARGS__) @@ -53,7 +54,7 @@ extern void compel_print_on_level(unsigned int loglevel, } while (0) #define pr_debug(fmt, ...) \ - compel_print_on_level(LOG_DEBUG, \ + compel_print_on_level(COMPEL_LOG_DEBUG, \ LOG_PREFIX fmt, ##__VA_ARGS__) #define pr_perror(fmt, ...) \ diff --git a/compel/include/uapi/log.h b/compel/include/uapi/log.h index cd3bf2aff..79dd1f4d5 100644 --- a/compel/include/uapi/log.h +++ b/compel/include/uapi/log.h @@ -1,7 +1,11 @@ #ifndef __COMPEL_UAPI_LOG_H__ #define __COMPEL_UAPI_LOG_H__ + +#include #include + typedef void (*compel_log_fn)(unsigned int lvl, const char *fmt, va_list parms); extern void compel_log_init(compel_log_fn log_fn, unsigned int level); extern unsigned int compel_log_get_loglevel(void); + #endif diff --git a/compel/include/uapi/loglevels.h b/compel/include/uapi/loglevels.h index f7cdcc448..7bf88475d 100644 --- a/compel/include/uapi/loglevels.h +++ b/compel/include/uapi/loglevels.h @@ -1,13 +1,20 @@ #ifndef UAPI_COMPEL_LOGLEVELS_H__ #define UAPI_COMPEL_LOGLEVELS_H__ -#define LOG_UNSET (-1) -#define LOG_MSG (0) /* Print message regardless of log level */ -#define LOG_ERROR (1) /* Errors only, when we're in trouble */ -#define LOG_WARN (2) /* Warnings, dazen and confused but trying to continue */ -#define LOG_INFO (3) /* Informative, everything is fine */ -#define LOG_DEBUG (4) /* Debug only */ +/* + * Log levels used by compel itself (see compel_log_init()), + * also by log functions in the std plugin. + */ -#define DEFAULT_LOGLEVEL LOG_WARN +enum __compel_log_levels +{ + COMPEL_LOG_MSG, /* Print message regardless of log level */ + COMPEL_LOG_ERROR, /* Errors only, when we're in trouble */ + COMPEL_LOG_WARN, /* Warnings */ + COMPEL_LOG_INFO, /* Informative, everything is fine */ + COMPEL_LOG_DEBUG, /* Debug only */ + + COMPEL_DEFAULT_LOGLEVEL = COMPEL_LOG_WARN +}; #endif /* UAPI_COMPEL_LOGLEVELS_H__ */ diff --git a/compel/plugins/std/log.c b/compel/plugins/std/log.c index 52a3f1a30..2d622d658 100644 --- a/compel/plugins/std/log.c +++ b/compel/plugins/std/log.c @@ -2,7 +2,7 @@ #include "common/bitsperlong.h" #include -#include "uapi/std/string.h" +#include #include #include @@ -14,7 +14,7 @@ struct simple_buf { }; static int logfd = -1; -static int cur_loglevel = DEFAULT_LOGLEVEL; +static int cur_loglevel = COMPEL_DEFAULT_LOGLEVEL; static struct timeval start; static void sbuf_log_flush(struct simple_buf *b); diff --git a/compel/src/lib/log.c b/compel/src/lib/log.c index 4c98407c6..d195343e4 100644 --- a/compel/src/lib/log.c +++ b/compel/src/lib/log.c @@ -11,7 +11,7 @@ #include "log.h" -static unsigned int current_loglevel = DEFAULT_LOGLEVEL; +static unsigned int current_loglevel = COMPEL_DEFAULT_LOGLEVEL; static compel_log_fn logfn; void compel_log_init(compel_log_fn log_fn, unsigned int level) diff --git a/compel/src/main.c b/compel/src/main.c index 33dc2aa57..ea3da89a5 100644 --- a/compel/src/main.c +++ b/compel/src/main.c @@ -110,7 +110,7 @@ static void cli_log(unsigned int lvl, const char *fmt, va_list parms) if (pr_quelled(lvl)) return; - if ((lvl == LOG_ERROR) || (lvl == LOG_WARN)) + if ((lvl == COMPEL_LOG_ERROR) || (lvl == COMPEL_LOG_WARN)) f = stderr; vfprintf(f, fmt, parms); @@ -130,7 +130,7 @@ static int usage(int rc) { " -l, --log-level NUM log level (default: %d)\n" " compel -h|--help\n" " compel -V|--version\n" -, DEFAULT_LOGLEVEL +, COMPEL_DEFAULT_LOGLEVEL ); return rc; @@ -283,7 +283,7 @@ static char *gen_prefix(const char *path) int main(int argc, char *argv[]) { - int log_level = DEFAULT_LOGLEVEL; + int log_level = COMPEL_DEFAULT_LOGLEVEL; bool compat = false; bool is_static = false; int opt, idx; diff --git a/compel/test/infect/spy.c b/compel/test/infect/spy.c index c628a0f86..b8a65c345 100644 --- a/compel/test/infect/spy.c +++ b/compel/test/infect/spy.c @@ -24,7 +24,7 @@ static int do_infection(int pid) struct infect_ctx *ictx; int *arg; - compel_log_init(print_vmsg, LOG_DEBUG); + compel_log_init(print_vmsg, COMPEL_LOG_DEBUG); printf("Stopping task\n"); state = compel_stop_task(pid); diff --git a/compel/test/rsys/spy.c b/compel/test/rsys/spy.c index 82c9725d7..f5c999d5a 100644 --- a/compel/test/rsys/spy.c +++ b/compel/test/rsys/spy.c @@ -20,7 +20,7 @@ static int do_rsetsid(int pid) long ret; struct parasite_ctl *ctl; - compel_log_init(print_vmsg, LOG_DEBUG); + compel_log_init(print_vmsg, COMPEL_LOG_DEBUG); printf("Stopping task\n"); state = compel_stop_task(pid);