From: "Tzvetomir Stoyanov (VMware)" <tz.stoyanov@gmail.com>
To: rostedt@goodmis.org
Cc: linux-trace-devel@vger.kernel.org
Subject: [PATCH v2 1/6] trace-cmd library: Add log levels
Date: Mon, 17 May 2021 16:40:00 +0300 [thread overview]
Message-ID: <20210517134005.611251-2-tz.stoyanov@gmail.com> (raw)
In-Reply-To: <20210517134005.611251-1-tz.stoyanov@gmail.com>
Add levels to library logs and introduce a new API to set the desired
log severity:
tracecmd_set_loglevel()
When a new trace-cmd library log level is set, propagate it to tracefs
and traceevent libraries as well.
Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
---
include/trace-cmd/trace-cmd.h | 2 ++
lib/trace-cmd/trace-util.c | 24 ++++++++++++++++++++++--
2 files changed, 24 insertions(+), 2 deletions(-)
diff --git a/include/trace-cmd/trace-cmd.h b/include/trace-cmd/trace-cmd.h
index 7305487c..6984db86 100644
--- a/include/trace-cmd/trace-cmd.h
+++ b/include/trace-cmd/trace-cmd.h
@@ -43,4 +43,6 @@ int tracecmd_buffer_instances(struct tracecmd_input *handle);
const char *tracecmd_buffer_instance_name(struct tracecmd_input *handle, int indx);
struct tracecmd_input *tracecmd_buffer_instance_handle(struct tracecmd_input *handle, int indx);
+void tracecmd_set_loglevel(enum tep_loglevel level);
+
#endif /* _TRACE_CMD_H */
diff --git a/lib/trace-cmd/trace-util.c b/lib/trace-cmd/trace-util.c
index 049fe049..6db754e4 100644
--- a/lib/trace-cmd/trace-util.c
+++ b/lib/trace-cmd/trace-util.c
@@ -30,7 +30,7 @@
#define PROC_STACK_FILE "/proc/sys/kernel/stack_tracer_enabled"
static bool debug;
-
+static int log_level = TEP_LOG_CRITICAL;
static FILE *logfp;
const static struct {
@@ -355,19 +355,36 @@ trace_load_plugins(struct tep_handle *tep, int flags)
return list;
}
+/**
+ * tracecmd_set_loglevel - set log level of the library
+ * @level: desired level of the library messages
+ */
+void tracecmd_set_loglevel(enum tep_loglevel level)
+{
+ log_level = level;
+ tracefs_set_loglevel(level);
+ tep_set_loglevel(level);
+}
+
void __weak tracecmd_warning(const char *fmt, ...)
{
va_list ap;
+ if (log_level < TEP_LOG_WARNING)
+ return;
+
va_start(ap, fmt);
tep_vprint("libtracecmd", TEP_LOG_WARNING, true, fmt, ap);
va_end(ap);
}
-void tracecmd_info(const char *fmt, ...)
+void __weak tracecmd_info(const char *fmt, ...)
{
va_list ap;
+ if (log_level < TEP_LOG_INFO)
+ return;
+
va_start(ap, fmt);
tep_vprint("libtracecmd", TEP_LOG_INFO, false, fmt, ap);
va_end(ap);
@@ -379,6 +396,9 @@ void __weak tracecmd_fatal(const char *fmt, ...)
int ret;
va_list ap;
+ if (log_level < TEP_LOG_CRITICAL)
+ return;
+
va_start(ap, fmt);
ret = tep_vprint("libtracecmd", TEP_LOG_CRITICAL, true, fmt, ap);
va_end(ap);
--
2.31.1
next prev parent reply other threads:[~2021-05-17 13:40 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-17 13:39 [PATCH v2 0/6] Changes to trace-cmd logs Tzvetomir Stoyanov (VMware)
2021-05-17 13:40 ` Tzvetomir Stoyanov (VMware) [this message]
2021-05-17 13:40 ` [PATCH v2 2/6] trace-cmd library: Document the API for log levels Tzvetomir Stoyanov (VMware)
2021-05-17 13:40 ` [PATCH v2 3/6] trace-cmd library: Renamed tracecmd_fatal() to tracecmd_critical() Tzvetomir Stoyanov (VMware)
2021-05-17 13:40 ` [PATCH v2 4/6] trace-cmd library: Set debug log level in debug mode Tzvetomir Stoyanov (VMware)
2021-05-17 13:40 ` [PATCH v2 5/6] trace-cmd report: Set the log level with -V and -q options Tzvetomir Stoyanov (VMware)
2021-05-17 13:40 ` [PATCH v2 6/6] trace-cmd: Add new function to set log level Tzvetomir Stoyanov (VMware)
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=20210517134005.611251-2-tz.stoyanov@gmail.com \
--to=tz.stoyanov@gmail.com \
--cc=linux-trace-devel@vger.kernel.org \
--cc=rostedt@goodmis.org \
/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;
as well as URLs for NNTP newsgroup(s).