From: "Tzvetomir Stoyanov (VMware)" <tz.stoyanov@gmail.com>
To: rostedt@goodmis.org
Cc: linux-trace-devel@vger.kernel.org
Subject: [PATCH v2 3/4] libtraceevent: Rename tep_vwarning() to tep_vprint()
Date: Fri, 7 May 2021 12:50:21 +0300 [thread overview]
Message-ID: <20210507095022.1079364-4-tz.stoyanov@gmail.com> (raw)
In-Reply-To: <20210507095022.1079364-1-tz.stoyanov@gmail.com>
Renamed the existing weak function tep_vwarning() to tep_vprint(), to
match its purpose. This function is used to print library logs with any
log severity, not only warnings.
Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
---
src/event-utils.h | 5 +++--
src/parse-utils.c | 27 ++++++++++++++++++++++-----
2 files changed, 25 insertions(+), 7 deletions(-)
diff --git a/src/event-utils.h b/src/event-utils.h
index 1951557..0617a28 100644
--- a/src/event-utils.h
+++ b/src/event-utils.h
@@ -9,10 +9,11 @@
#include <ctype.h>
#include <stdarg.h>
+void tep_warning(const char *fmt, ...);
void tep_info(const char *fmt, ...);
/* Can be overridden */
-void tep_warning(const char *fmt, ...);
-int tep_vwarning(const char *name, const char *fmt, va_list ap);
+int tep_vprint(const char *name, enum tep_loglevel level,
+ bool print_err, const char *fmt, va_list ap);
#define min(x, y) ({ \
typeof(x) _min1 = (x); \
diff --git a/src/parse-utils.c b/src/parse-utils.c
index b997823..7510157 100644
--- a/src/parse-utils.c
+++ b/src/parse-utils.c
@@ -24,11 +24,28 @@ void tep_set_loglevel(enum tep_loglevel level)
log_level = level;
}
-int __weak tep_vwarning(const char *name, const char *fmt, va_list 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 __weak tep_vprint(const char *name, enum tep_loglevel level,
+ bool print_err, const char *fmt, va_list ap)
{
int ret = errno;
- if (errno)
+ if (errno && print_err)
perror(name);
fprintf(stderr, " ");
@@ -38,7 +55,7 @@ int __weak tep_vwarning(const char *name, const char *fmt, va_list ap)
return ret;
}
-void __weak tep_warning(const char *fmt, ...)
+void tep_warning(const char *fmt, ...)
{
va_list ap;
@@ -46,7 +63,7 @@ void __weak tep_warning(const char *fmt, ...)
return;
va_start(ap, fmt);
- tep_vwarning("libtraceevent", fmt, ap);
+ tep_vprint("libtraceevent", TEP_LOG_WARNING, true, fmt, ap);
va_end(ap);
}
@@ -59,6 +76,6 @@ void tep_info(const char *fmt, ...)
return;
va_start(ap, fmt);
- tep_vwarning("libtraceevent", fmt, ap);
+ tep_vprint("libtraceevent", TEP_LOG_INFO, false, 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 ` [PATCH v2 1/4] libtraceevent: Add log levels Tzvetomir Stoyanov (VMware)
2021-05-07 9:50 ` [PATCH v2 2/4] libtraceevent: Add logs with severity info Tzvetomir Stoyanov (VMware)
2021-05-07 9:50 ` Tzvetomir Stoyanov (VMware) [this message]
2021-05-13 1:52 ` [PATCH v2 3/4] libtraceevent: Rename tep_vwarning() to tep_vprint() 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-4-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).