@@ -41,4 +41,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 */
@@ -9,7 +9,6 @@
#include <byteswap.h>
#include "trace-cmd-private.h"
-/* Can be overridden */
void tracecmd_warning(const char *fmt, ...);
void tracecmd_fatal(const char *fmt, ...);
void tracecmd_info(const char *fmt, ...);
@@ -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,10 +355,24 @@ trace_load_plugins(struct tep_handle *tep, int flags)
return list;
}
-void __weak tracecmd_warning(const char *fmt, ...)
+/**
+ * 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 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, fmt, ap);
va_end(ap);
@@ -368,17 +382,23 @@ void 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, fmt, ap);
va_end(ap);
}
-void __weak tracecmd_fatal(const char *fmt, ...)
+void 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, fmt, ap);
va_end(ap);
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. Removed the "weak" definition of the library log functions. Setting the desired log level can be used to silence the library logs, instead of overwriting the log functions. Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com> --- include/trace-cmd/trace-cmd.h | 2 ++ lib/trace-cmd/include/trace-cmd-local.h | 1 - lib/trace-cmd/trace-util.c | 26 ++++++++++++++++++++++--- 3 files changed, 25 insertions(+), 4 deletions(-)