From: Simon Marchi Date: Wed, 3 Apr 2024 16:05:13 +0000 (-0400) Subject: cpp-common/bt2c: add `BT_CPPLOGE_ERRNO_APPEND_CAUSE_SPEC` X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=commitdiff_plain;h=2f505dde81e79fab65451fc32338f3b2184d5485 cpp-common/bt2c: add `BT_CPPLOGE_ERRNO_APPEND_CAUSE_SPEC` Add the `BT_CPPLOGE_ERRNO_APPEND_CAUSE_SPEC` macro, allowing to log an error and append an error cause based on `errno`, without throwing. Change-Id: I5837ef4b78a6d89b5574072f23d4aba6665e6bb4 Signed-off-by: Simon Marchi Reviewed-on: https://review.lttng.org/c/babeltrace/+/12232 Tested-by: jenkins --- diff --git a/src/cpp-common/bt2c/logging.hpp b/src/cpp-common/bt2c/logging.hpp index 838c555b..40074a27 100644 --- a/src/cpp-common/bt2c/logging.hpp +++ b/src/cpp-common/bt2c/logging.hpp @@ -924,6 +924,34 @@ private: #define BT_CPPLOGE_STR_APPEND_CAUSE_AND_RETHROW(_msg) \ BT_CPPLOGE_STR_APPEND_CAUSE_AND_RETHROW_SPEC(_BT_CPPLOG_DEF_LOGGER, (_msg)) +/* + * Calls logErrno() on `_logger` with the `Level::Error` level to log an + * error and append a cause to the error of the current thread. + */ +#define BT_CPPLOGE_ERRNO_APPEND_CAUSE_SPEC(_logger, _init_msg, _fmt, ...) \ + (_logger).logErrno(__FILE__, __func__, __LINE__, \ + (_init_msg), (_fmt), ##__VA_ARGS__) + +/* + * BT_CPPLOGE_ERRNO_APPEND_CAUSE_SPEC() using the default logger. + */ +#define BT_CPPLOGE_ERRNO_APPEND_CAUSE(_init_msg, _fmt, ...) \ + BT_CPPLOGE_ERRNO_APPEND_CAUSE_SPEC(_BT_CPPLOG_DEF_LOGGER, (_init_msg), (_fmt), ##__VA_ARGS__) + +/* + * Calls logErrnoStr() on `_logger` with the `Level::Error` level to log + * an error and append a cause to the error of the current thread. + */ +#define BT_CPPLOGE_ERRNO_STR_APPEND_CAUSE_SPEC(_logger, _init_msg, _msg) \ + (_logger).logErrnoStr(__FILE__, __func__, __LINE__, \ + (_init_msg), (_msg)) + +/* + * BT_CPPLOGE_ERRNO_STR_APPEND_CAUSE_SPEC() using the default logger. + */ +#define BT_CPPLOGE_ERRNO_STR_APPEND_CAUSE(_init_msg, _msg) \ + BT_CPPLOGE_ERRNO_STR_APPEND_CAUSE_SPEC(_BT_CPPLOG_DEF_LOGGER, (_init_msg), (_msg)) + /* * Calls logErrorErrnoAndThrow() on `_logger` to log an error, append a * cause to the error of the current thread, and throw an instance of