2 * SPDX-License-Identifier: MIT
4 * Copyright (c) 2022 Francis Deslauriers <francis.deslauriers@efficios.com>
5 * Copyright (c) 2022 Simon Marchi <simon.marchi@efficios.com>
6 * Copyright (c) 2022 Philippe Proulx <eeppeliteloop@gmail.com>
9 #ifndef BABELTRACE_CPP_COMMON_CFG_LOGGING_ERROR_REPORTING_THROW_HPP
10 #define BABELTRACE_CPP_COMMON_CFG_LOGGING_ERROR_REPORTING_THROW_HPP
12 #include <babeltrace2/babeltrace.h>
13 #include "cfg-logging-error-reporting.hpp"
16 * Logs with the error level using the configuration `_log_cfg`, appends
17 * a cause to the error of the current thread, and throws an instance of
20 #define BT_CLOGE_APPEND_CAUSE_AND_THROW_EX(_log_cfg, _exc_cls, _fmt, ...) \
22 BT_CLOGE_APPEND_CAUSE_EX((_log_cfg), _fmt, ##__VA_ARGS__); \
26 #define BT_CLOGE_APPEND_CAUSE_AND_THROW(_exc_cls, _fmt, ...) \
27 BT_CLOGE_APPEND_CAUSE_AND_THROW_EX((BT_CLOG_CFG), _exc_cls, _fmt, ##__VA_ARGS__)
30 * Logs with the error level using the configuration `_log_cfg`, appends
31 * a cause to the error of the current thread, and rethrows.
33 #define BT_CLOGE_APPEND_CAUSE_AND_RETHROW_EX(_log_cfg, _fmt, ...) \
35 BT_CLOGE_APPEND_CAUSE_EX((_log_cfg), _fmt, ##__VA_ARGS__); \
39 #define BT_CLOGE_APPEND_CAUSE_AND_RETHROW(_fmt, ...) \
40 BT_CLOGE_APPEND_CAUSE_AND_RETHROW_EX((BT_CLOG_CFG), _fmt, ##__VA_ARGS__)
43 * Logs with the error level using the configuration `_log_cfg`, appends
44 * a cause to the error of the current thread, and throws an instance of
47 #define BT_CLOGE_STR_APPEND_CAUSE_AND_THROW_EX(_log_cfg, _exc_cls, _str) \
49 BT_CLOGE_STR_APPEND_CAUSE_EX((_log_cfg), _str); \
53 #define BT_CLOGE_STR_APPEND_CAUSE_AND_THROW(_exc_cls, _str) \
54 BT_CLOGE_APPEND_CAUSE_AND_THROW_EX((BT_CLOG_CFG), _exc_cls, _str)
57 * Logs with the error level using the configuration `_log_cfg`, appends
58 * a cause to the error of the current thread, and rethrows.
60 #define BT_CLOGE_STR_APPEND_CAUSE_AND_RETHROW_EX(_log_cfg, _str) \
62 BT_CLOGE_STR_APPEND_CAUSE_EX((_log_cfg), _str); \
66 #define BT_CLOGE_STR_APPEND_CAUSE_AND_RETHROW(_str) \
67 BT_CLOGE_APPEND_CAUSE_AND_RETHROW_EX((BT_CLOG_CFG), _str)
70 * Logs an errno message with the error level, using the configuration
71 * `_log_cfg`, having the initial message `_init_msg`, appends a cause
72 * to the error of the current thread, and throws an instance of
75 #define BT_CLOGE_ERRNO_APPEND_CAUSE_AND_THROW_EX(_log_cfg, _exc_cls, _init_msg, _fmt, ...) \
77 BT_CLOGE_ERRNO_APPEND_CAUSE_EX((_log_cfg), _init_msg, _fmt, ##__VA_ARGS__); \
81 #define BT_CLOGE_ERRNO_APPEND_CAUSE_AND_THROW(_exc_cls, _init_msg, _fmt, ...) \
82 BT_CLOGE_ERRNO_APPEND_CAUSE_AND_THROW_EX((BT_CLOG_CFG), _exc_cls, _init_msg, _fmt, \
86 * Logs an errno message with the error level, using the configuration
87 * `_log_cfg`, having the initial message `_init_msg`, appends a cause
88 * to the error of the current thread, and rethrows.
90 #define BT_CLOGE_ERRNO_APPEND_CAUSE_AND_RETHROW_EX(_log_cfg, _init_msg, _fmt, ...) \
92 BT_CLOGE_ERRNO_APPEND_CAUSE_EX((_log_cfg), _init_msg, _fmt, ##__VA_ARGS__); \
96 #define BT_CLOGE_ERRNO_APPEND_CAUSE_AND_RETHROW(_init_msg, _fmt, ...) \
97 BT_CLOGE_ERRNO_APPEND_CAUSE_AND_RETHROW_EX((BT_CLOG_CFG), _init_msg, _fmt, ##__VA_ARGS__)
100 * Logs memory bytes with the error level using the configuration
101 * `_log_cfg`, appends a cause to the error of the current thread, and
102 * throws an instance of `_exc_cls`.
104 #define BT_CLOGE_MEM_APPEND_CAUSE_AND_THROW_EX(_log_cfg, _exc_cls, _data, _data_sz, _fmt, ...) \
106 BT_CLOGE_MEM_APPEND_CAUSE_EX((_log_cfg), (_data), (_data_sz), _fmt, ##__VA_ARGS__); \
110 #define BT_CLOGE_MEM_APPEND_CAUSE_AND_THROW(_exc_cls, _data, _data_sz, _fmt, ...) \
111 BT_CLOGE_MEM_APPEND_CAUSE_AND_THROW_EX((BT_CLOG_CFG), _exc_cls, (_data), (_data_sz), _fmt, \
115 * Logs memory bytes with the error level using the configuration
116 * `_log_cfg`, appends a cause to the error of the current thread, and
119 #define BT_CLOGE_MEM_APPEND_CAUSE_AND_RETHROW_EX(_log_cfg, _data, _data_sz, _fmt, ...) \
121 BT_CLOGE_MEM_APPEND_CAUSE_EX((_log_cfg), (_data), (_data_sz), _fmt, ##__VA_ARGS__); \
125 #define BT_CLOGE_MEM_APPEND_CAUSE_AND_RETHROW(_data, _data_sz, _fmt, ...) \
126 BT_CLOGE_MEM_APPEND_CAUSE_AND_RETHROW_EX((BT_CLOG_CFG), (_data), (_data_sz), _fmt, \
129 #endif /* BABELTRACE_CPP_COMMON_CFG_LOGGING_ERROR_REPORTING_THROW_HPP */