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