From: Mykyta Yatsenko mykyta.yatsenko5@gmail.com
To: bpf@vger.kernel.org, ast@kernel.org, andrii@kernel.org,
daniel@iogearbox.net, kafai@meta.com, kernel-team@meta.com
Cc: Mykyta Yatsenko <yatsenko@meta.com>
Subject: [PATCH bpf-next] libbpf: configure log verbosity with env variable
Date: Thu, 23 May 2024 21:53:37 +0100 [thread overview]
Message-ID: <20240523205337.951410-1-yatsenko@meta.com> (raw)
From: Mykyta Yatsenko <yatsenko@meta.com>
Configure logging verbosity by setting LIBBPF_LOG environment
variable. Only applying to default logger. Once user set their custom
logging callback, it is up to them to filter.
Signed-off-by: Mykyta Yatsenko <yatsenko@meta.com>
---
tools/lib/bpf/libbpf.c | 18 +++++++++++++++++-
1 file changed, 17 insertions(+), 1 deletion(-)
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 5401f2df463d..8805607073da 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -229,7 +229,23 @@ static const char * const prog_type_name[] = {
static int __base_pr(enum libbpf_print_level level, const char *format,
va_list args)
{
- if (level == LIBBPF_DEBUG)
+ static enum libbpf_print_level env_level = LIBBPF_INFO;
+ static bool initialized;
+
+ if (!initialized) {
+ char *verbosity;
+
+ initialized = true;
+ verbosity = getenv("LIBBPF_LOG");
+ if (verbosity) {
+ if (strcmp(verbosity, "warn") == 0)
+ env_level = LIBBPF_WARN;
+ else if (strcmp(verbosity, "debug") == 0)
+ env_level = LIBBPF_DEBUG;
+ }
+ }
+
+ if (env_level < level)
return 0;
return vfprintf(stderr, format, args);
--
2.45.0
next reply other threads:[~2024-05-23 20:53 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-23 20:53 Mykyta [this message]
2024-05-23 21:50 ` [PATCH bpf-next] libbpf: configure log verbosity with env variable Andrii Nakryiko
-- strict thread matches above, loose matches on Subject: below --
2024-05-24 13:18 Mykyta
2024-05-28 23:27 ` Andrii Nakryiko
2024-05-29 1:25 ` patchwork-bot+netdevbpf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240523205337.951410-1-yatsenko@meta.com \
--to=bpf@vger.kernel.org \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=daniel@iogearbox.net \
--cc=kafai@meta.com \
--cc=kernel-team@meta.com \
--cc=yatsenko@meta.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox