From e020d1340a9b5ebd7d7dbf00a2c34d2fe512a495 Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Tue, 21 Apr 2020 10:56:20 -0400 Subject: [PATCH] lib: add bt_lib_log_v() This is a `va_list` (vprintf() style) version of bt_lib_log(). Signed-off-by: Philippe Proulx Change-Id: I41dc0e247c79e8f22cc930b27ec4f13a2dd6d573 Reviewed-on: https://review.lttng.org/c/babeltrace/+/3441 --- src/lib/lib-logging.c | 13 ++++++++++--- src/lib/logging.h | 3 +++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/lib/lib-logging.c b/src/lib/lib-logging.c index 1730f6d0..4085cd26 100644 --- a/src/lib/lib-logging.c +++ b/src/lib/lib-logging.c @@ -1484,6 +1484,15 @@ update_fmt: *out_fmt_ch = fmt_ch; } +void bt_lib_log_v(const char *func, const char *file, unsigned line, + int lvl, const char *tag, const char *fmt, va_list *args) +{ + BT_ASSERT(fmt); + bt_common_custom_vsnprintf(lib_logging_buf, LIB_LOGGING_BUF_SIZE, '!', + handle_conversion_specifier_bt, NULL, fmt, args); + _bt_log_write_d(func, file, line, lvl, tag, "%s", lib_logging_buf); +} + void bt_lib_log(const char *func, const char *file, unsigned line, int lvl, const char *tag, const char *fmt, ...) { @@ -1491,10 +1500,8 @@ void bt_lib_log(const char *func, const char *file, unsigned line, BT_ASSERT(fmt); va_start(args, fmt); - bt_common_custom_vsnprintf(lib_logging_buf, LIB_LOGGING_BUF_SIZE, '!', - handle_conversion_specifier_bt, NULL, fmt, &args); + bt_lib_log_v(func, file, line, lvl, tag, fmt, &args); va_end(args); - _bt_log_write_d(func, file, line, lvl, tag, "%s", lib_logging_buf); } void bt_lib_maybe_log_and_append_cause(const char *func, const char *file, diff --git a/src/lib/logging.h b/src/lib/logging.h index 25699c84..8462e47c 100644 --- a/src/lib/logging.h +++ b/src/lib/logging.h @@ -57,6 +57,9 @@ int bt_lib_log_level; void bt_lib_log(const char *func, const char *file, unsigned line, int lvl, const char *tag, const char *fmt, ...); +void bt_lib_log_v(const char *func, const char *file, unsigned line, + int lvl, const char *tag, const char *fmt, va_list *args); + #define BT_LIB_LOG_AND_APPEND(_lvl, _fmt, ...) \ do { \ bt_lib_maybe_log_and_append_cause( \ -- 2.34.1