cpp-common/bt2c: add `BT_CPPLOGE_APPEND_CAUSE_SPEC`
authorSimon Marchi <simon.marchi@efficios.com>
Wed, 3 Apr 2024 17:12:05 +0000 (13:12 -0400)
committerSimon Marchi <simon.marchi@efficios.com>
Wed, 17 Apr 2024 17:57:53 +0000 (13:57 -0400)
Add the `BT_CPPLOGE_APPEND_CAUSE_SPEC` macro, allowing to log an error,
append a cause, but not throw.

Change-Id: I6a09dd8775a85202c2049e902ab9edfcbd32080b
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12231
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
src/cpp-common/bt2c/logging.hpp

index 9d72f3dc2f20b4bba0ce9b6fcdc4c42d0007fce2..838c555bafb4f3cfa6666542df27c7ae76ea0432 100644 (file)
@@ -839,6 +839,33 @@ private:
 #define BT_CPPLOGF_ERRNO_STR(_init_msg, _msg)                                                      \
     BT_CPPLOGF_ERRNO_STR_SPEC(_BT_CPPLOG_DEF_LOGGER, (_init_msg), (_msg))
 
+/*
+ * Calls log() on `_logger` with the `Error` level to log an error and
+ * append a cause to the error of the current thread.
+ */
+#define BT_CPPLOGE_APPEND_CAUSE_SPEC(_logger, _fmt, ...)                                           \
+    (_logger).log<bt2c::Logger::Level::Error, true>(__FILE__, __func__, __LINE__, (_fmt),          \
+                                                    ##__VA_ARGS__)
+
+/*
+ * BT_CPPLOGE_APPEND_CAUSE_SPEC() using the default logger.
+ */
+#define BT_CPPLOGE_APPEND_CAUSE(_fmt, ...)                                                         \
+    BT_CPPLOGE_APPEND_CAUSE_SPEC(_BT_CPPLOG_DEF_LOGGER, (_fmt), ##__VA_ARGS__)
+
+/*
+ * Calls logStr() on `_logger` with the `Error` level to log an error and
+ * append a cause to the error of the current thread.
+ */
+#define BT_CPPLOGE_STR_APPEND_CAUSE_SPEC(_logger, _msg)                                            \
+    (_logger).logStr<bt2c::Logger::Level::Error, true>(__FILE__, __func__, __LINE__, (_msg))
+
+/*
+ * BT_CPPLOGE_STR_APPEND_CAUSE_SPEC() using the default logger.
+ */
+#define BT_CPPLOGE_STR_APPEND_CAUSE(_msg)                                                          \
+    BT_CPPLOGE_STR_APPEND_CAUSE_SPEC(_BT_CPPLOG_DEF_LOGGER, (_msg))
+
 /*
  * Calls logErrorAndThrow() on `_logger` to log an error, append a cause
  * to the error of the current thread, and throw an instance of
This page took 0.025712 seconds and 4 git commands to generate.