bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH bpf-next] libbpf: Add libbpf_set_log_level() function to adjust logging
@ 2019-10-24 13:21 Toke Høiland-Jørgensen
  2019-10-25 16:58 ` Andrii Nakryiko
  0 siblings, 1 reply; 5+ messages in thread
From: Toke Høiland-Jørgensen @ 2019-10-24 13:21 UTC (permalink / raw)
  To: daniel, ast; +Cc: Toke Høiland-Jørgensen, bpf, netdev

Currently, the only way to change the logging output of libbpf is to
override the print function with libbpf_set_print(). This is somewhat
cumbersome if one just wants to change the logging level (e.g., to enable
debugging), so add another function that just adjusts the default output
printing by adjusting the filtering of messages.

Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
---
 tools/lib/bpf/libbpf.c   | 12 +++++++++++-
 tools/lib/bpf/libbpf.h   |  2 ++
 tools/lib/bpf/libbpf.map |  1 +
 3 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index d1c4440a678e..93909d9a423d 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -67,10 +67,12 @@
 
 #define __printf(a, b)	__attribute__((format(printf, a, b)))
 
+static enum libbpf_print_level __libbpf_log_level = LIBBPF_INFO;
+
 static int __base_pr(enum libbpf_print_level level, const char *format,
 		     va_list args)
 {
-	if (level == LIBBPF_DEBUG)
+	if (level > __libbpf_log_level)
 		return 0;
 
 	return vfprintf(stderr, format, args);
@@ -86,6 +88,14 @@ libbpf_print_fn_t libbpf_set_print(libbpf_print_fn_t fn)
 	return old_print_fn;
 }
 
+enum libbpf_print_level libbpf_set_log_level(enum libbpf_print_level level)
+{
+	enum libbpf_print_level old_level = __libbpf_log_level;
+
+	__libbpf_log_level = level;
+	return old_level;
+}
+
 __printf(2, 3)
 void libbpf_print(enum libbpf_print_level level, const char *format, ...)
 {
diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h
index c63e2ff84abc..0bba6c2259f1 100644
--- a/tools/lib/bpf/libbpf.h
+++ b/tools/lib/bpf/libbpf.h
@@ -58,6 +58,8 @@ typedef int (*libbpf_print_fn_t)(enum libbpf_print_level level,
 				 const char *, va_list ap);
 
 LIBBPF_API libbpf_print_fn_t libbpf_set_print(libbpf_print_fn_t fn);
+LIBBPF_API enum libbpf_print_level
+libbpf_set_log_level(enum libbpf_print_level level);
 
 /* Hide internal to user */
 struct bpf_object;
diff --git a/tools/lib/bpf/libbpf.map b/tools/lib/bpf/libbpf.map
index d1473ea4d7a5..c3f79418c2be 100644
--- a/tools/lib/bpf/libbpf.map
+++ b/tools/lib/bpf/libbpf.map
@@ -197,4 +197,5 @@ LIBBPF_0.0.6 {
 		bpf_object__open_mem;
 		bpf_program__get_expected_attach_type;
 		bpf_program__get_type;
+		libbpf_set_log_level;
 } LIBBPF_0.0.5;
-- 
2.23.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-10-27 20:55 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-24 13:21 [PATCH bpf-next] libbpf: Add libbpf_set_log_level() function to adjust logging Toke Høiland-Jørgensen
2019-10-25 16:58 ` Andrii Nakryiko
2019-10-27 11:08   ` Toke Høiland-Jørgensen
2019-10-27 20:00     ` Andrii Nakryiko
2019-10-27 20:55       ` Toke Høiland-Jørgensen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).