2016-10-18 20:58:26 +03:00
|
|
|
#ifndef COMPEL_LOG_H__
|
|
|
|
#define COMPEL_LOG_H__
|
|
|
|
|
|
|
|
#include "uapi/compel/compel.h"
|
|
|
|
#include "uapi/compel/loglevels.h"
|
|
|
|
|
|
|
|
#ifndef LOG_PREFIX
|
|
|
|
# define LOG_PREFIX
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static inline int pr_quelled(unsigned int loglevel)
|
|
|
|
{
|
2017-02-13 16:59:36 -08:00
|
|
|
return compel_log_get_loglevel() < loglevel
|
|
|
|
&& loglevel != COMPEL_LOG_MSG;
|
2016-10-18 20:58:26 +03:00
|
|
|
}
|
|
|
|
|
2017-02-13 16:59:35 -08:00
|
|
|
extern void compel_print_on_level(unsigned int loglevel,
|
2017-02-13 16:59:37 -08:00
|
|
|
const char *format, ...)
|
|
|
|
__attribute__ ((__format__ (__printf__, 2, 3)));
|
2016-10-18 20:58:26 +03:00
|
|
|
|
2017-02-13 16:59:35 -08:00
|
|
|
#define pr_msg(fmt, ...) \
|
2017-02-13 16:59:36 -08:00
|
|
|
compel_print_on_level(COMPEL_LOG_MSG, \
|
2016-10-18 20:58:26 +03:00
|
|
|
fmt, ##__VA_ARGS__)
|
|
|
|
|
2017-02-13 16:59:35 -08:00
|
|
|
#define pr_info(fmt, ...) \
|
2017-02-13 16:59:36 -08:00
|
|
|
compel_print_on_level(COMPEL_LOG_INFO, \
|
2016-10-18 20:58:26 +03:00
|
|
|
LOG_PREFIX fmt, ##__VA_ARGS__)
|
|
|
|
|
2017-02-13 16:59:35 -08:00
|
|
|
#define pr_err(fmt, ...) \
|
2017-02-13 16:59:36 -08:00
|
|
|
compel_print_on_level(COMPEL_LOG_ERROR, \
|
2017-02-13 16:59:35 -08:00
|
|
|
"Error (%s:%d): " LOG_PREFIX fmt, \
|
2016-10-18 20:58:26 +03:00
|
|
|
__FILE__, __LINE__, ##__VA_ARGS__)
|
|
|
|
|
2017-02-13 16:59:35 -08:00
|
|
|
#define pr_err_once(fmt, ...) \
|
|
|
|
do { \
|
|
|
|
static bool __printed; \
|
|
|
|
if (!__printed) { \
|
|
|
|
pr_err(fmt, ##__VA_ARGS__); \
|
|
|
|
__printed = 1; \
|
|
|
|
} \
|
2016-10-18 20:58:26 +03:00
|
|
|
} while (0)
|
|
|
|
|
2017-02-13 16:59:35 -08:00
|
|
|
#define pr_warn(fmt, ...) \
|
2017-02-13 16:59:36 -08:00
|
|
|
compel_print_on_level(COMPEL_LOG_WARN, \
|
2017-02-13 16:59:35 -08:00
|
|
|
"Warn (%s:%d): " LOG_PREFIX fmt, \
|
2016-10-18 20:58:26 +03:00
|
|
|
__FILE__, __LINE__, ##__VA_ARGS__)
|
|
|
|
|
2017-02-13 16:59:35 -08:00
|
|
|
#define pr_warn_once(fmt, ...) \
|
|
|
|
do { \
|
|
|
|
static bool __printed; \
|
|
|
|
if (!__printed) { \
|
|
|
|
pr_warn(fmt, ##__VA_ARGS__); \
|
|
|
|
__printed = 1; \
|
|
|
|
} \
|
2016-10-18 20:58:26 +03:00
|
|
|
} while (0)
|
|
|
|
|
2017-02-13 16:59:35 -08:00
|
|
|
#define pr_debug(fmt, ...) \
|
2017-02-13 16:59:36 -08:00
|
|
|
compel_print_on_level(COMPEL_LOG_DEBUG, \
|
2016-10-18 20:58:26 +03:00
|
|
|
LOG_PREFIX fmt, ##__VA_ARGS__)
|
|
|
|
|
2017-02-13 16:59:35 -08:00
|
|
|
#define pr_perror(fmt, ...) \
|
2016-10-18 20:58:26 +03:00
|
|
|
pr_err(fmt ": %m\n", ##__VA_ARGS__)
|
|
|
|
|
|
|
|
#endif /* COMPEL_LOG_H__ */
|