Commit | Line | Data |
---|---|---|
b4953462 SM |
1 | /* |
2 | * SPDX-License-Identifier: MIT | |
3 | * | |
4 | * Copyright (c) 2022 Simon Marchi <simon.marchi@efficios.com> | |
5 | * Copyright (c) 2022 Philippe Proulx <eeppeliteloop@gmail.com> | |
6 | */ | |
7 | ||
8 | #ifndef BABELTRACE_CPP_COMMON_CFG_LOGGING_ERROR_REPORTING_HPP | |
9 | #define BABELTRACE_CPP_COMMON_CFG_LOGGING_ERROR_REPORTING_HPP | |
10 | ||
11 | #include <babeltrace2/babeltrace.h> | |
c802cacb | 12 | |
b4953462 | 13 | #include "cfg-error-reporting.hpp" |
c802cacb | 14 | #include "cfg-logging.hpp" |
b4953462 SM |
15 | |
16 | /* | |
17 | * Logs with the error level using the configuration `_log_cfg` and | |
18 | * appends a cause to the error of the current thread. | |
19 | */ | |
20 | #define BT_CLOGE_APPEND_CAUSE_EX(_log_cfg, _fmt, ...) \ | |
21 | do { \ | |
22 | BT_CLOGE_EX((_log_cfg), _fmt, ##__VA_ARGS__); \ | |
23 | BT_APPEND_CAUSE_EX((_log_cfg), _fmt, ##__VA_ARGS__); \ | |
24 | } while (false) | |
25 | ||
26 | #define BT_CLOGE_APPEND_CAUSE(_fmt, ...) \ | |
27 | BT_CLOGE_APPEND_CAUSE_EX((BT_CLOG_CFG), _fmt, ##__VA_ARGS__) | |
28 | ||
29 | /* | |
30 | * Logs with the error level using the configuration `_log_cfg` and | |
31 | * appends a cause to the error of the current thread. | |
32 | */ | |
33 | #define BT_CLOGE_STR_APPEND_CAUSE_EX(_log_cfg, _str) \ | |
34 | do { \ | |
35 | BT_CLOGE_STR_EX((_log_cfg), _str); \ | |
36 | BT_APPEND_CAUSE_EX((_log_cfg), "%s", _str); \ | |
37 | } while (false) | |
38 | ||
39 | #define BT_CLOGE_STR_APPEND_CAUSE(_str) BT_CLOGE_STR_APPEND_CAUSE_EX((BT_CLOG_CFG), _str) | |
40 | ||
41 | /* | |
42 | * Logs an errno message with the error level, using the configuration | |
43 | * `_log_cfg`, having the initial message `_init_msg`, and appends a | |
44 | * cause to the error of the current thread. | |
45 | */ | |
46 | #define BT_CLOGE_ERRNO_APPEND_CAUSE_EX(_log_cfg, _init_msg, _fmt, ...) \ | |
47 | do { \ | |
48 | BT_CLOGE_ERRNO_EX((_log_cfg), _init_msg, _fmt, ##__VA_ARGS__); \ | |
49 | BT_APPEND_CAUSE_ERRNO_EX((_log_cfg), _init_msg, _fmt, ##__VA_ARGS__); \ | |
50 | } while (false) | |
51 | ||
52 | #define BT_CLOGE_ERRNO_APPEND_CAUSE(_init_msg, _fmt, ...) \ | |
53 | BT_CLOGE_ERRNO_APPEND_CAUSE_EX((BT_CLOG_CFG), _init_msg, _fmt, ##__VA_ARGS__) | |
54 | ||
55 | /* | |
56 | * Logs memory bytes with the error level using the configuration | |
57 | * `_log_cfg` and appends a cause to the error of the current thread. | |
58 | */ | |
59 | #define BT_CLOGE_MEM_APPEND_CAUSE_EX(_log_cfg, _data, _data_sz, _fmt, ...) \ | |
60 | do { \ | |
61 | BT_CLOGE_MEM_EX((_log_cfg), (_data), (_data_sz), _fmt, ##__VA_ARGS__); \ | |
62 | BT_APPEND_CAUSE_EX((_log_cfg), _fmt, ##__VA_ARGS__); \ | |
63 | } while (false) | |
64 | ||
65 | #define BT_CLOGE_MEM_APPEND_CAUSE(_data, _data_sz, _fmt, ...) \ | |
66 | BT_CLOGE_MEM_APPEND_CAUSE_EX((BT_CLOG_CFG), (_data), (_data_sz), _fmt, ##__VA_ARGS__) | |
67 | ||
68 | #endif /* BABELTRACE_CPP_COMMON_CFG_LOGGING_ERROR_REPORTING_HPP */ |