From: Steven Rostedt <rostedt@goodmis.org>
To: <linux-trace-devel@vger.kernel.org>
Cc: "Steven Rostedt (VMware)" <rostedt@goodmis.org>
Subject: [PATCH 3/3] libtraceevent: Add __tep_vprint() for overrides to use
Date: Fri, 14 May 2021 16:50:36 -0400 [thread overview]
Message-ID: <20210514205036.1383167-4-rostedt@goodmis.org> (raw)
In-Reply-To: <20210514205036.1383167-1-rostedt@goodmis.org>
From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>
If a program wants to add something special to tep_vprint() but then also
call the default tep_vprint() it can't. If it overrides the function, it
loses the functionality for it.
Add __tep_vprint() for this use case.
Example:
int tep_vprint(const char *name, enum tep_loglevel level,
bool print_err, const char *fmt, va_list ap)
{
if (quiet && !strcmp(name, "myprog"))
return 0;
return __tep_vprint(name, level, print_err, fmt, ap);
}
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
src/event-utils.h | 6 ++++++
src/parse-utils.c | 23 +++++++++++++++++++++++
2 files changed, 29 insertions(+)
diff --git a/src/event-utils.h b/src/event-utils.h
index 607be0c..d377201 100644
--- a/src/event-utils.h
+++ b/src/event-utils.h
@@ -14,10 +14,16 @@
void tep_warning(const char *fmt, ...);
void tep_info(const char *fmt, ...);
+
/* Can be overridden */
int tep_vprint(const char *name, enum tep_loglevel level,
bool print_err, const char *fmt, va_list ap);
+/* The actual call of tep_vprint() for overrides to use */
+int __tep_vprint(const char *name, enum tep_loglevel level,
+ bool print_err, const char *fmt, va_list ap);
+
+
#define __deprecated(msg) __attribute__((deprecated("msg")))
/* For backward compatibilty, do not use */
diff --git a/src/parse-utils.c b/src/parse-utils.c
index 04237ba..89bf1cd 100644
--- a/src/parse-utils.c
+++ b/src/parse-utils.c
@@ -9,6 +9,7 @@
#include <stdarg.h>
#include <errno.h>
+#include "event-utils.h"
#include "event-parse.h"
#define __weak __attribute__((weak))
@@ -42,6 +43,28 @@ void tep_set_loglevel(enum tep_loglevel level)
*/
int __weak tep_vprint(const char *name, enum tep_loglevel level,
bool print_err, const char *fmt, va_list ap)
+{
+ return __tep_vprint(name, level, print_err, fmt, ap);
+}
+
+/**
+ * __tep_vprint - print library log messages
+ * @name: name of the library.
+ * @level: severity of the log message. This parameter is not used in this implementation, but as
+ * the function is weak and can be overridden, having the log level could be useful
+ * for other implementations.
+ * @print_err: whether to print the errno, if non zero.
+ * @fmt: printf format string of the message.
+ * @ap: list of printf parameters.
+ *
+ * This function is used to print all messages from traceevent, tracefs and trace-cmd libraries.
+ * It is defined as weak, so the application that uses those libraries can override it in order
+ * to implement its own logic for printing library logs.
+ *
+ * Return the value of errno at the function enter.
+ */
+int __tep_vprint(const char *name, enum tep_loglevel level,
+ bool print_err, const char *fmt, va_list ap)
{
int ret = errno;
--
2.29.2
prev parent reply other threads:[~2021-05-14 20:50 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-14 20:50 [PATCH 0/3] libtraceevent: Add __tep_vprint() for overrides Steven Rostedt
2021-05-14 20:50 ` [PATCH 1/3] libtraceevent: Add include of event-parse.h into event-utils.h Steven Rostedt
2021-05-14 20:50 ` [PATCH 2/3] libtraceevent: Have the header protection be more name space safe Steven Rostedt
2021-05-14 20:50 ` Steven Rostedt [this message]
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=20210514205036.1383167-4-rostedt@goodmis.org \
--to=rostedt@goodmis.org \
--cc=linux-trace-devel@vger.kernel.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).