From: "Tzvetomir Stoyanov (VMware)" <tz.stoyanov@gmail.com>
To: rostedt@goodmis.org
Cc: linux-trace-devel@vger.kernel.org
Subject: [PATCH v2 1/4] libtraceevent: Add log levels
Date: Fri, 7 May 2021 12:50:19 +0300 [thread overview]
Message-ID: <20210507095022.1079364-2-tz.stoyanov@gmail.com> (raw)
In-Reply-To: <20210507095022.1079364-1-tz.stoyanov@gmail.com>
Defined levels of the library logs and new API to set the desired log
level. By default, only critical logs are enabled.
Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
---
src/event-parse.h | 12 ++++++++++++
src/parse-utils.c | 16 ++++++++++++++++
2 files changed, 28 insertions(+)
diff --git a/src/event-parse.h b/src/event-parse.h
index 05b156b..77be2b9 100644
--- a/src/event-parse.h
+++ b/src/event-parse.h
@@ -749,4 +749,16 @@ int tep_filter_copy(struct tep_event_filter *dest, struct tep_event_filter *sour
int tep_filter_compare(struct tep_event_filter *filter1, struct tep_event_filter *filter2);
+/* Control library logs */
+enum tep_loglevel {
+ TEP_LOG_NONE = 0,
+ TEP_LOG_CRITICAL,
+ TEP_LOG_ERROR,
+ TEP_LOG_WARNING,
+ TEP_LOG_INFO,
+ TEP_LOG_DEBUG,
+ TEP_LOG_ALL
+};
+void tep_set_loglevel(enum tep_loglevel level);
+
#endif /* _PARSE_EVENTS_H */
diff --git a/src/parse-utils.c b/src/parse-utils.c
index 6a4a2cd..bc89c44 100644
--- a/src/parse-utils.c
+++ b/src/parse-utils.c
@@ -9,8 +9,21 @@
#include <stdarg.h>
#include <errno.h>
+#include "event-parse.h"
+
#define __weak __attribute__((weak))
+static int log_level = TEP_LOG_CRITICAL;
+
+/**
+ * tep_set_loglevel - set log level of the library
+ * @level: desired level of the library messages
+ */
+void tep_set_loglevel(enum tep_loglevel level)
+{
+ log_level = level;
+}
+
int __weak tep_vwarning(const char *name, const char *fmt, va_list ap)
{
int ret = errno;
@@ -29,6 +42,9 @@ void __weak tep_warning(const char *fmt, ...)
{
va_list ap;
+ if (log_level < TEP_LOG_WARNING)
+ return;
+
va_start(ap, fmt);
tep_vwarning("libtraceevent", fmt, ap);
va_end(ap);
--
2.31.1
next prev parent reply other threads:[~2021-05-07 9:50 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-07 9:50 [PATCH v2 0/4] Add severity to library logs Tzvetomir Stoyanov (VMware)
2021-05-07 9:50 ` Tzvetomir Stoyanov (VMware) [this message]
2021-05-07 9:50 ` [PATCH v2 2/4] libtraceevent: Add logs with severity info Tzvetomir Stoyanov (VMware)
2021-05-07 9:50 ` [PATCH v2 3/4] libtraceevent: Rename tep_vwarning() to tep_vprint() Tzvetomir Stoyanov (VMware)
2021-05-13 1:52 ` Steven Rostedt
2021-05-07 9:50 ` [PATCH v2 4/4] libtraceevent: Document new log functionality 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=20210507095022.1079364-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).