tests: normalize inclusions of tap/tap.h
[babeltrace.git] / src / cpp-common / cfg-logging.hpp
CommitLineData
b4953462
SM
1/*
2 * SPDX-License-Identifier: MIT
3 *
4 * Copyright (c) 2022 Philippe Proulx <eeppeliteloop@gmail.com>
5 */
6
7#ifndef BABELTRACE_CPP_COMMON_CFG_LOGGING_HPP
8#define BABELTRACE_CPP_COMMON_CFG_LOGGING_HPP
9
10#ifdef BT_CLOG_CFG
11# ifdef BT_LOG_OUTPUT_LEVEL
12# error `BT_LOG_OUTPUT_LEVEL` may not be defined when `BT_CLOG_CFG` is.
13# endif
14# define BT_LOG_OUTPUT_LEVEL ((BT_CLOG_CFG).logLevel())
15#endif
16
17#include <babeltrace2/babeltrace.h>
18#include "logging/log.h"
19
20#define _BT_CLOG_OBJ_FMT_PREFIX "[%s] "
21
22/*
23 * Logs with the level `_lvl` using the configuration `_log_cfg`.
24 */
25#define BT_CLOG_EX(_lvl, _log_cfg, _fmt, ...) \
26 if (BT_LOG_ON_CUR_LVL(_lvl, (_log_cfg).logLevel())) { \
27 if ((_log_cfg).selfComp()) { \
28 _bt_log_write((_lvl), _BT_LOG_TAG, _BT_CLOG_OBJ_FMT_PREFIX _fmt, \
29 (_log_cfg).compName(), ##__VA_ARGS__); \
30 } else if ((_log_cfg).compCls()) { \
31 _bt_log_write((_lvl), _BT_LOG_TAG, _BT_CLOG_OBJ_FMT_PREFIX _fmt, \
32 (_log_cfg).compClsName(), ##__VA_ARGS__); \
33 } else { \
34 _bt_log_write((_lvl), _BT_LOG_TAG, _fmt, ##__VA_ARGS__); \
35 } \
36 }
37
38#define BT_CLOGF_EX(_log_cfg, _fmt, ...) BT_CLOG_EX(BT_LOG_FATAL, (_log_cfg), _fmt, ##__VA_ARGS__)
39#define BT_CLOGE_EX(_log_cfg, _fmt, ...) BT_CLOG_EX(BT_LOG_ERROR, (_log_cfg), _fmt, ##__VA_ARGS__)
40#define BT_CLOGW_EX(_log_cfg, _fmt, ...) BT_CLOG_EX(BT_LOG_WARNING, (_log_cfg), _fmt, ##__VA_ARGS__)
41#define BT_CLOGI_EX(_log_cfg, _fmt, ...) BT_CLOG_EX(BT_LOG_INFO, (_log_cfg), _fmt, ##__VA_ARGS__)
42#define BT_CLOGD_EX(_log_cfg, _fmt, ...) BT_CLOG_EX(BT_LOG_DEBUG, (_log_cfg), _fmt, ##__VA_ARGS__)
43#define BT_CLOGT_EX(_log_cfg, _fmt, ...) BT_CLOG_EX(BT_LOG_TRACE, (_log_cfg), _fmt, ##__VA_ARGS__)
44#define BT_CLOG(_lvl, _fmt, ...) BT_CLOG_EX((_lvl), (BT_CLOG_CFG), _fmt, ##__VA_ARGS__)
45#define BT_CLOGF(_fmt, ...) BT_CLOG(BT_LOG_FATAL, _fmt, ##__VA_ARGS__)
46#define BT_CLOGE(_fmt, ...) BT_CLOG(BT_LOG_ERROR, _fmt, ##__VA_ARGS__)
47#define BT_CLOGW(_fmt, ...) BT_CLOG(BT_LOG_WARNING, _fmt, ##__VA_ARGS__)
48#define BT_CLOGI(_fmt, ...) BT_CLOG(BT_LOG_INFO, _fmt, ##__VA_ARGS__)
49#define BT_CLOGD(_fmt, ...) BT_CLOG(BT_LOG_DEBUG, _fmt, ##__VA_ARGS__)
50#define BT_CLOGT(_fmt, ...) BT_CLOG(BT_LOG_TRACE, _fmt, ##__VA_ARGS__)
51
52/*
53 * Logs with the level `_lvl` using the configuration `_log_cfg`.
54 */
55#define BT_CLOG_STR_EX(_lvl, _log_cfg, _str) BT_CLOG_EX((_lvl), (_log_cfg), "%s", _str)
56
57#define BT_CLOGF_STR_EX(_log_cfg, _str) BT_CLOG_STR_EX(BT_LOG_FATAL, (_log_cfg), _str)
58#define BT_CLOGE_STR_EX(_log_cfg, _str) BT_CLOG_STR_EX(BT_LOG_ERROR, (_log_cfg), _str)
59#define BT_CLOGW_STR_EX(_log_cfg, _str) BT_CLOG_STR_EX(BT_LOG_WARNING, (_log_cfg), _str)
60#define BT_CLOGI_STR_EX(_log_cfg, _str) BT_CLOG_STR_EX(BT_LOG_INFO, (_log_cfg), _str)
61#define BT_CLOGD_STR_EX(_log_cfg, _str) BT_CLOG_STR_EX(BT_LOG_DEBUG, (_log_cfg), _str)
62#define BT_CLOGT_STR_EX(_log_cfg, _str) BT_CLOG_STR_EX(BT_LOG_TRACE, (_log_cfg), _str)
63#define BT_CLOG_STR(_lvl, _str) BT_CLOG_STR_EX((_lvl), (BT_CLOG_CFG), _str)
64#define BT_CLOGF_STR(_str) BT_CLOG_STR(BT_LOG_FATAL, _str)
65#define BT_CLOGE_STR(_str) BT_CLOG_STR(BT_LOG_ERROR, _str)
66#define BT_CLOGW_STR(_str) BT_CLOG_STR(BT_LOG_WARNING, _str)
67#define BT_CLOGI_STR(_str) BT_CLOG_STR(BT_LOG_INFO, _str)
68#define BT_CLOGD_STR(_str) BT_CLOG_STR(BT_LOG_DEBUG, _str)
69#define BT_CLOGT_STR(_str) BT_CLOG_STR(BT_LOG_TRACE, _str)
70
71/*
72 * Logs an errno message with the level `_lvl`, using the configuration
73 * `_log_cfg`, and having the initial message `_init_msg`.
74 */
75#define BT_CLOG_ERRNO_EX(_lvl, _log_cfg, _init_msg, _fmt, ...) \
76 if (BT_LOG_ON(_lvl)) { \
77 const auto errStr = g_strerror(errno); \
78 if ((_log_cfg).selfComp()) { \
79 _bt_log_write((_lvl), _BT_LOG_TAG, _BT_CLOG_OBJ_FMT_PREFIX "%s: %s" _fmt, \
80 (_log_cfg).compName(), _init_msg, errStr, ##__VA_ARGS__); \
81 } else if ((_log_cfg).compCls()) { \
82 _bt_log_write((_lvl), _BT_LOG_TAG, _BT_CLOG_OBJ_FMT_PREFIX "%s: %s" _fmt, \
83 (_log_cfg).compClsName(), _init_msg, errStr, ##__VA_ARGS__); \
84 } else { \
85 _bt_log_write((_lvl), _BT_LOG_TAG, "%s: %s" _fmt, _init_msg, errStr, ##__VA_ARGS__); \
86 } \
87 }
88
89#define BT_CLOGF_ERRNO_EX(_log_cfg, _init_msg, _fmt, ...) \
90 BT_CLOG_ERRNO_EX(BT_LOG_FATAL, (_log_cfg), _init_msg, _fmt, ##__VA_ARGS__)
91#define BT_CLOGE_ERRNO_EX(_log_cfg, _init_msg, _fmt, ...) \
92 BT_CLOG_ERRNO_EX(BT_LOG_ERROR, (_log_cfg), _init_msg, _fmt, ##__VA_ARGS__)
93#define BT_CLOGW_ERRNO_EX(_log_cfg, _init_msg, _fmt, ...) \
94 BT_CLOG_ERRNO_EX(BT_LOG_WARNING, (_log_cfg), _init_msg, _fmt, ##__VA_ARGS__)
95#define BT_CLOGI_ERRNO_EX(_log_cfg, _init_msg, _fmt, ...) \
96 BT_CLOG_ERRNO_EX(BT_LOG_INFO, (_log_cfg), _init_msg, _fmt, ##__VA_ARGS__)
97#define BT_CLOGD_ERRNO_EX(_log_cfg, _init_msg, _fmt, ...) \
98 BT_CLOG_ERRNO_EX(BT_LOG_DEBUG, (_log_cfg), _init_msg, _fmt, ##__VA_ARGS__)
99#define BT_CLOGT_ERRNO_EX(_log_cfg, _init_msg, _fmt, ...) \
100 BT_CLOG_ERRNO_EX(BT_LOG_TRACE, (_log_cfg), _init_msg, _fmt, ##__VA_ARGS__)
101#define BT_CLOG_ERRNO(_lvl, _init_msg, _fmt, ...) \
102 BT_CLOG_ERRNO_EX((_lvl), (BT_CLOG_CFG), _init_msg, _fmt, ##__VA_ARGS__)
103#define BT_CLOGF_ERRNO(_init_msg, _fmt, ...) \
104 BT_CLOG_ERRNO(BT_LOG_FATAL, _init_msg, _fmt, ##__VA_ARGS__)
105#define BT_CLOGE_ERRNO(_init_msg, _fmt, ...) \
106 BT_CLOG_ERRNO(BT_LOG_ERROR, _init_msg, _fmt, ##__VA_ARGS__)
107#define BT_CLOGW_ERRNO(_init_msg, _fmt, ...) \
108 BT_CLOG_ERRNO(BT_LOG_WARNING, _init_msg, _fmt, ##__VA_ARGS__)
109#define BT_CLOGI_ERRNO(_init_msg, _fmt, ...) \
110 BT_CLOG_ERRNO(BT_LOG_INFO, _init_msg, _fmt, ##__VA_ARGS__)
111#define BT_CLOGD_ERRNO(_init_msg, _fmt, ...) \
112 BT_CLOG_ERRNO(BT_LOG_DEBUG, _init_msg, _fmt, ##__VA_ARGS__)
113#define BT_CLOGT_ERRNO(_init_msg, _fmt, ...) \
114 BT_CLOG_ERRNO(BT_LOG_TRACE, _init_msg, _fmt, ##__VA_ARGS__)
115
116/*
117 * Logs memory bytes with the level `_lvl` using the configuration
118 * `_log_cfg`.
119 */
120#define BT_CLOG_MEM_EX(_lvl, _log_cfg, _data, _data_sz, _fmt, ...) \
121 if (BT_LOG_ON(_lvl)) { \
122 if ((_log_cfg).selfComp()) { \
123 _bt_log_write_mem((_lvl), _BT_LOG_TAG, (_data), (_data_sz), \
124 _BT_CLOG_OBJ_FMT_PREFIX _fmt, (_log_cfg).compName(), ##__VA_ARGS__); \
125 } else if ((_log_cfg).compCls()) { \
126 _bt_log_write_mem((_lvl), _BT_LOG_TAG, (_data), (_data_sz), \
127 _BT_CLOG_OBJ_FMT_PREFIX _fmt, (_log_cfg).compClsName(), \
128 ##__VA_ARGS__); \
129 } else { \
130 _bt_log_write_mem((_lvl), _BT_LOG_TAG, (_data), (_data_sz), _fmt, ##__VA_ARGS__); \
131 } \
132 }
133
134#define BT_CLOGF_MEM_EX(_log_cfg, _data, _data_sz, _fmt, ...) \
135 BT_CLOG_MEM_EX(BT_LOG_FATAL, (_log_cfg), (_data), (_data_sz), ##__VA_ARGS__)
136#define BT_CLOGE_MEM_EX(_log_cfg, _data, _data_sz, _fmt, ...) \
137 BT_CLOG_MEM_EX(BT_LOG_ERROR, (_log_cfg), (_data), (_data_sz), ##__VA_ARGS__)
138#define BT_CLOGW_MEM_EX(_log_cfg, _data, _data_sz, _fmt, ...) \
139 BT_CLOG_MEM_EX(BT_LOG_WARNING, (_log_cfg), (_data), (_data_sz), ##__VA_ARGS__)
140#define BT_CLOGI_MEM_EX(_log_cfg, _data, _data_sz, _fmt, ...) \
141 BT_CLOG_MEM_EX(BT_LOG_INFO, (_log_cfg), (_data), (_data_sz), ##__VA_ARGS__)
142#define BT_CLOGD_MEM_EX(_log_cfg, _data, _data_sz, _fmt, ...) \
143 BT_CLOG_MEM_EX(BT_LOG_DEBUG, (_log_cfg), (_data), (_data_sz), ##__VA_ARGS__)
144#define BT_CLOGT_MEM_EX(_log_cfg, _data, _data_sz, _fmt, ...) \
145 BT_CLOG_MEM_EX(BT_LOG_TRACE, (_log_cfg), (_data), (_data_sz), ##__VA_ARGS__)
146
147#define BT_CLOG_MEM(_lvl, _data, _data_sz, _fmt, ...) \
148 BT_CLOG_MEM_EX(_lvl, (BT_CLOG_CFG), (_data), (_data_sz), _fmt, ##__VA_ARGS__)
149#define BT_CLOGF_MEM(_data, _data_sz, _fmt, ...) \
150 BT_CLOG_MEM(BT_LOG_FATAL, (_data), (_data_sz), _fmt, ##__VA_ARGS__)
151#define BT_CLOGE_MEM(_data, _data_sz, _fmt, ...) \
152 BT_CLOG_MEM(BT_LOG_ERROR, (_data), (_data_sz), _fmt, ##__VA_ARGS__)
153#define BT_CLOGW_MEM(_data, _data_sz, _fmt, ...) \
154 BT_CLOG_MEM(BT_LOG_WARNING, (_data), (_data_sz), _fmt, ##__VA_ARGS__)
155#define BT_CLOGI_MEM(_data, _data_sz, _fmt, ...) \
156 BT_CLOG_MEM(BT_LOG_INFO, (_data), (_data_sz), _fmt, ##__VA_ARGS__)
157#define BT_CLOGD_MEM(_data, _data_sz, _fmt, ...) \
158 BT_CLOG_MEM(BT_LOG_DEBUG, (_data), (_data_sz), _fmt, ##__VA_ARGS__)
159#define BT_CLOGT_MEM(_data, _data_sz, _fmt, ...) \
160 BT_CLOG_MEM(BT_LOG_TRACE, (_data), (_data_sz), _fmt, ##__VA_ARGS__)
161
162#endif /* BABELTRACE_CPP_COMMON_CFG_LOGGING_HPP */
This page took 0.032049 seconds and 4 git commands to generate.