Commit b1245247 authored by Kir Kolyshkin's avatar Kir Kolyshkin Committed by Andrei Vagin

compel/uapi: add prefix to log levels

These are part of compel UAPI so should be prefixed with COMPEL_
in order to not pollute the namespace. While at it, move from
set of defines to an enum, which looks a bit cleaner.

Also, kill LOG_UNDEF as it's not used anywhere.
Signed-off-by: 's avatarKir Kolyshkin <kir@openvz.org>
Signed-off-by: 's avatarAndrei Vagin <avagin@virtuozzo.com>
parent c1d4832d
......@@ -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, ...) \
......
#ifndef __COMPEL_UAPI_LOG_H__
#define __COMPEL_UAPI_LOG_H__
#include <stdarg.h>
#include <compel/loglevels.h>
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
#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 */
#define DEFAULT_LOGLEVEL LOG_WARN
/*
* Log levels used by compel itself (see compel_log_init()),
* also by log functions in the std plugin.
*/
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__ */
......@@ -2,7 +2,7 @@
#include "common/bitsperlong.h"
#include <compel/plugins/std/syscall.h>
#include "uapi/std/string.h"
#include <compel/plugins/std/string.h>
#include <compel/plugins/std/log.h>
#include <compel/loglevels.h>
......@@ -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);
......
......@@ -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)
......
......@@ -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;
......
......@@ -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);
......
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment