0bd0ec0ddab5a201d287a04af261be0725d01b1a
[babeltrace.git] / src / cpp-common / cfg-logging-error-reporting.hpp
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>
12 #include "cfg-logging.hpp"
13 #include "cfg-error-reporting.hpp"
14
15 /*
16 * Logs with the error level using the configuration `_log_cfg` and
17 * appends a cause to the error of the current thread.
18 */
19 #define BT_CLOGE_APPEND_CAUSE_EX(_log_cfg, _fmt, ...) \
20 do { \
21 BT_CLOGE_EX((_log_cfg), _fmt, ##__VA_ARGS__); \
22 BT_APPEND_CAUSE_EX((_log_cfg), _fmt, ##__VA_ARGS__); \
23 } while (false)
24
25 #define BT_CLOGE_APPEND_CAUSE(_fmt, ...) \
26 BT_CLOGE_APPEND_CAUSE_EX((BT_CLOG_CFG), _fmt, ##__VA_ARGS__)
27
28 /*
29 * Logs with the error level using the configuration `_log_cfg` and
30 * appends a cause to the error of the current thread.
31 */
32 #define BT_CLOGE_STR_APPEND_CAUSE_EX(_log_cfg, _str) \
33 do { \
34 BT_CLOGE_STR_EX((_log_cfg), _str); \
35 BT_APPEND_CAUSE_EX((_log_cfg), "%s", _str); \
36 } while (false)
37
38 #define BT_CLOGE_STR_APPEND_CAUSE(_str) BT_CLOGE_STR_APPEND_CAUSE_EX((BT_CLOG_CFG), _str)
39
40 /*
41 * Logs an errno message with the error level, using the configuration
42 * `_log_cfg`, having the initial message `_init_msg`, and appends a
43 * cause to the error of the current thread.
44 */
45 #define BT_CLOGE_ERRNO_APPEND_CAUSE_EX(_log_cfg, _init_msg, _fmt, ...) \
46 do { \
47 BT_CLOGE_ERRNO_EX((_log_cfg), _init_msg, _fmt, ##__VA_ARGS__); \
48 BT_APPEND_CAUSE_ERRNO_EX((_log_cfg), _init_msg, _fmt, ##__VA_ARGS__); \
49 } while (false)
50
51 #define BT_CLOGE_ERRNO_APPEND_CAUSE(_init_msg, _fmt, ...) \
52 BT_CLOGE_ERRNO_APPEND_CAUSE_EX((BT_CLOG_CFG), _init_msg, _fmt, ##__VA_ARGS__)
53
54 /*
55 * Logs memory bytes with the error level using the configuration
56 * `_log_cfg` and appends a cause to the error of the current thread.
57 */
58 #define BT_CLOGE_MEM_APPEND_CAUSE_EX(_log_cfg, _data, _data_sz, _fmt, ...) \
59 do { \
60 BT_CLOGE_MEM_EX((_log_cfg), (_data), (_data_sz), _fmt, ##__VA_ARGS__); \
61 BT_APPEND_CAUSE_EX((_log_cfg), _fmt, ##__VA_ARGS__); \
62 } while (false)
63
64 #define BT_CLOGE_MEM_APPEND_CAUSE(_data, _data_sz, _fmt, ...) \
65 BT_CLOGE_MEM_APPEND_CAUSE_EX((BT_CLOG_CFG), (_data), (_data_sz), _fmt, ##__VA_ARGS__)
66
67 #endif /* BABELTRACE_CPP_COMMON_CFG_LOGGING_ERROR_REPORTING_HPP */
This page took 0.030472 seconds and 3 git commands to generate.