File: log.h

package info (click to toggle)
criu 4.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 11,500 kB
  • sloc: ansic: 139,280; python: 7,484; sh: 3,824; java: 2,799; makefile: 2,659; asm: 1,137; perl: 206; xml: 117; exp: 45
file content (53 lines) | stat: -rw-r--r-- 1,702 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#ifndef COMPEL_LOG_H__
#define COMPEL_LOG_H__

#include <errno.h>
#include <string.h>

#include "uapi/compel/log.h"

#ifndef LOG_PREFIX
#define LOG_PREFIX
#endif

static inline int pr_quelled(unsigned int loglevel)
{
	return compel_log_get_loglevel() < loglevel && loglevel != COMPEL_LOG_MSG;
}

extern void compel_print_on_level(unsigned int loglevel, const char *format, ...)
	__attribute__((__format__(__printf__, 2, 3)));

#define pr_msg(fmt, ...) compel_print_on_level(COMPEL_LOG_MSG, fmt, ##__VA_ARGS__)

#define pr_info(fmt, ...) compel_print_on_level(COMPEL_LOG_INFO, LOG_PREFIX fmt, ##__VA_ARGS__)

#define pr_err(fmt, ...) \
	compel_print_on_level(COMPEL_LOG_ERROR, "Error (%s:%d): " LOG_PREFIX fmt, __FILE__, __LINE__, ##__VA_ARGS__)

#define pr_err_once(fmt, ...)                       \
	do {                                        \
		static bool __printed;              \
		if (!__printed) {                   \
			pr_err(fmt, ##__VA_ARGS__); \
			__printed = 1;              \
		}                                   \
	} while (0)

#define pr_warn(fmt, ...) \
	compel_print_on_level(COMPEL_LOG_WARN, "Warn  (%s:%d): " LOG_PREFIX fmt, __FILE__, __LINE__, ##__VA_ARGS__)

#define pr_warn_once(fmt, ...)                       \
	do {                                         \
		static bool __printed;               \
		if (!__printed) {                    \
			pr_warn(fmt, ##__VA_ARGS__); \
			__printed = 1;               \
		}                                    \
	} while (0)

#define pr_debug(fmt, ...) compel_print_on_level(COMPEL_LOG_DEBUG, LOG_PREFIX fmt, ##__VA_ARGS__)

#define pr_perror(fmt, ...) pr_err(fmt ": %s\n", ##__VA_ARGS__, strerror(errno))

#endif /* COMPEL_LOG_H__ */