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>
14 #include "cfg-logging-error-reporting.hpp"
17 * Logs with the error level using the configuration `_log_cfg`, appends
18 * a cause to the error of the current thread, and throws an instance of
21 #define BT_CLOGE_APPEND_CAUSE_AND_THROW_EX(_log_cfg, _exc_cls, _fmt, ...) \
23 BT_CLOGE_APPEND_CAUSE_EX((_log_cfg), _fmt, ##__VA_ARGS__); \
27 #define BT_CLOGE_APPEND_CAUSE_AND_THROW(_exc_cls, _fmt, ...) \
28 BT_CLOGE_APPEND_CAUSE_AND_THROW_EX((BT_CLOG_CFG), _exc_cls, _fmt, ##__VA_ARGS__)
31 * Logs with the error level using the configuration `_log_cfg`, appends
32 * a cause to the error of the current thread, and rethrows.
34 #define BT_CLOGE_APPEND_CAUSE_AND_RETHROW_EX(_log_cfg, _fmt, ...) \
36 BT_CLOGE_APPEND_CAUSE_EX((_log_cfg), _fmt, ##__VA_ARGS__); \
40 #define BT_CLOGE_APPEND_CAUSE_AND_RETHROW(_fmt, ...) \
41 BT_CLOGE_APPEND_CAUSE_AND_RETHROW_EX((BT_CLOG_CFG), _fmt, ##__VA_ARGS__)
44 * Logs with the error level using the configuration `_log_cfg`, appends
45 * a cause to the error of the current thread, and throws an instance of
48 #define BT_CLOGE_STR_APPEND_CAUSE_AND_THROW_EX(_log_cfg, _exc_cls, _str) \
50 BT_CLOGE_STR_APPEND_CAUSE_EX((_log_cfg), _str); \
54 #define BT_CLOGE_STR_APPEND_CAUSE_AND_THROW(_exc_cls, _str) \
55 BT_CLOGE_APPEND_CAUSE_AND_THROW_EX((BT_CLOG_CFG), _exc_cls, _str)
58 * Logs with the error level using the configuration `_log_cfg`, appends
59 * a cause to the error of the current thread, and rethrows.
61 #define BT_CLOGE_STR_APPEND_CAUSE_AND_RETHROW_EX(_log_cfg, _str) \
63 BT_CLOGE_STR_APPEND_CAUSE_EX((_log_cfg), _str); \
67 #define BT_CLOGE_STR_APPEND_CAUSE_AND_RETHROW(_str) \
68 BT_CLOGE_APPEND_CAUSE_AND_RETHROW_EX((BT_CLOG_CFG), _str)
71 * Logs an errno message with the error level, using the configuration
72 * `_log_cfg`, having the initial message `_init_msg`, appends a cause
73 * to the error of the current thread, and throws an instance of
76 #define BT_CLOGE_ERRNO_APPEND_CAUSE_AND_THROW_EX(_log_cfg, _exc_cls, _init_msg, _fmt, ...) \
78 BT_CLOGE_ERRNO_APPEND_CAUSE_EX((_log_cfg), _init_msg, _fmt, ##__VA_ARGS__); \
82 #define BT_CLOGE_ERRNO_APPEND_CAUSE_AND_THROW(_exc_cls, _init_msg, _fmt, ...) \
83 BT_CLOGE_ERRNO_APPEND_CAUSE_AND_THROW_EX((BT_CLOG_CFG), _exc_cls, _init_msg, _fmt, \
87 * Logs an errno message with the error level, using the configuration
88 * `_log_cfg`, having the initial message `_init_msg`, appends a cause
89 * to the error of the current thread, and rethrows.
91 #define BT_CLOGE_ERRNO_APPEND_CAUSE_AND_RETHROW_EX(_log_cfg, _init_msg, _fmt, ...) \
93 BT_CLOGE_ERRNO_APPEND_CAUSE_EX((_log_cfg), _init_msg, _fmt, ##__VA_ARGS__); \
97 #define BT_CLOGE_ERRNO_APPEND_CAUSE_AND_RETHROW(_init_msg, _fmt, ...) \
98 BT_CLOGE_ERRNO_APPEND_CAUSE_AND_RETHROW_EX((BT_CLOG_CFG), _init_msg, _fmt, ##__VA_ARGS__)
101 * Logs memory bytes with the error level using the configuration
102 * `_log_cfg`, appends a cause to the error of the current thread, and
103 * throws an instance of `_exc_cls`.
105 #define BT_CLOGE_MEM_APPEND_CAUSE_AND_THROW_EX(_log_cfg, _exc_cls, _data, _data_sz, _fmt, ...) \
107 BT_CLOGE_MEM_APPEND_CAUSE_EX((_log_cfg), (_data), (_data_sz), _fmt, ##__VA_ARGS__); \
111 #define BT_CLOGE_MEM_APPEND_CAUSE_AND_THROW(_exc_cls, _data, _data_sz, _fmt, ...) \
112 BT_CLOGE_MEM_APPEND_CAUSE_AND_THROW_EX((BT_CLOG_CFG), _exc_cls, (_data), (_data_sz), _fmt, \
116 * Logs memory bytes with the error level using the configuration
117 * `_log_cfg`, appends a cause to the error of the current thread, and
120 #define BT_CLOGE_MEM_APPEND_CAUSE_AND_RETHROW_EX(_log_cfg, _data, _data_sz, _fmt, ...) \
122 BT_CLOGE_MEM_APPEND_CAUSE_EX((_log_cfg), (_data), (_data_sz), _fmt, ##__VA_ARGS__); \
126 #define BT_CLOGE_MEM_APPEND_CAUSE_AND_RETHROW(_data, _data_sz, _fmt, ...) \
127 BT_CLOGE_MEM_APPEND_CAUSE_AND_RETHROW_EX((BT_CLOG_CFG), (_data), (_data_sz), _fmt, \
130 #endif /* BABELTRACE_CPP_COMMON_CFG_LOGGING_ERROR_REPORTING_THROW_HPP */