summaryrefslogtreecommitdiffstats
path: root/lib/util/logging.h
blob: 16c4e74453d29d57556dcdc4cedf52d450e3a518 (plain)
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
/* SPDX-License-Identifier: GPL-2.0 */

#ifndef __LOGGING_H
#define __LOGGING_H

/* This matches the libbpf logging levels, but with an additional VERBOSE level;
 * we demote all libbpf messages by one level so debug messages only show up on
 * VERBOSE.
 */
enum logging_print_level {
	LOG_WARN,
	LOG_INFO,
	LOG_DEBUG,
	LOG_VERBOSE,
};

extern void logging_print(enum logging_print_level level, const char *format,
			  ...) __attribute__((format(printf, 2, 3)));

#define __pr(level, fmt, ...)                             \
	do {                                              \
		logging_print(level, fmt, ##__VA_ARGS__); \
	} while (0)

#define pr_warn(fmt, ...) __pr(LOG_WARN, fmt, ##__VA_ARGS__)
#define pr_info(fmt, ...) __pr(LOG_INFO, fmt, ##__VA_ARGS__)
#define pr_debug(fmt, ...) __pr(LOG_DEBUG, fmt, ##__VA_ARGS__)

void init_lib_logging(void);
void silence_libbpf_logging(void);
void silence_libxdp_logging(void);
enum logging_print_level set_log_level(enum logging_print_level level);
enum logging_print_level increase_log_level();

#endif