diff mbox series

[3/4] libtraceevent: Rename tep_vwarning() to tep_vprint()

Message ID 20210428073001.755905-4-tz.stoyanov@gmail.com (mailing list archive)
State Superseded
Headers show
Series Add severity to library logs | expand

Commit Message

Tzvetomir Stoyanov (VMware) April 28, 2021, 7:30 a.m. UTC
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 |  4 ++--
 src/parse-utils.c | 10 +++++-----
 2 files changed, 7 insertions(+), 7 deletions(-)

Comments

Steven Rostedt May 4, 2021, 8:22 p.m. UTC | #1
On Wed, 28 Apr 2021 10:30:00 +0300
"Tzvetomir Stoyanov (VMware)" <tz.stoyanov@gmail.com> wrote:

> @@ -24,11 +24,11 @@ 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 __weak tep_vprint(const char *name, enum tep_loglevel level, const char *fmt, va_list ap)
>  {
>  	int ret = errno;
>  
> -	if (errno)
> +	if (errno && level <= TEP_LOG_WARNING)
>  		perror(name);
>  
>  	fprintf(stderr, "  ");

If this is passing in a log level, why not just have:

	if (level < loglevel)
		return 0;

?

-- Steve
diff mbox series

Patch

diff --git a/src/event-utils.h b/src/event-utils.h
index 1951557..0e09838 100644
--- a/src/event-utils.h
+++ b/src/event-utils.h
@@ -9,10 +9,10 @@ 
 #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, 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..b4e95b7 100644
--- a/src/parse-utils.c
+++ b/src/parse-utils.c
@@ -24,11 +24,11 @@  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 __weak tep_vprint(const char *name, enum tep_loglevel level, const char *fmt, va_list ap)
 {
 	int ret = errno;
 
-	if (errno)
+	if (errno && level <= TEP_LOG_WARNING)
 		perror(name);
 
 	fprintf(stderr, "  ");
@@ -38,7 +38,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 +46,7 @@  void __weak tep_warning(const char *fmt, ...)
 		return;
 
 	va_start(ap, fmt);
-	tep_vwarning("libtraceevent", fmt, ap);
+	tep_vprint("libtraceevent", TEP_LOG_WARNING, fmt, ap);
 	va_end(ap);
 }
 
@@ -59,6 +59,6 @@  void tep_info(const char *fmt, ...)
 		return;
 
 	va_start(ap, fmt);
-	tep_vwarning("libtraceevent", fmt, ap);
+	tep_vprint("libtraceevent", TEP_LOG_INFO, fmt, ap);
 	va_end(ap);
 }