1 #ifndef BABELTRACE_LOGGING_COMP_LOGGING_H
2 #define BABELTRACE_LOGGING_COMP_LOGGING_H
5 * Copyright 2019 Philippe Proulx <pproulx@efficios.com>
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27 # error Please define a tag with BT_LOG_TAG before including this file.
31 #include <babeltrace2/babeltrace.h>
32 #include "logging/log.h"
34 #define _BT_COMP_LOG_COMP_PREFIX "[%s] "
35 #define _BT_COMP_LOG_COMP_NA_STR "N/A"
37 /* Logs with level `_lvl` for self component `_self_comp` */
38 #define BT_COMP_LOG(_lvl, _self_comp, _fmt, ...) \
39 BT_LOG_WRITE((_lvl), BT_LOG_TAG, _BT_COMP_LOG_COMP_PREFIX _fmt, \
41 bt_component_get_name( \
42 bt_self_component_as_component(_self_comp)) : \
43 _BT_COMP_LOG_COMP_NA_STR, \
46 /* Logs with level `_lvl` for self component class `_self_comp_class` */
47 #define BT_COMP_CLASS_LOG(_lvl, _self_comp_class, _fmt, ...) \
48 BT_LOG_WRITE((_lvl), BT_LOG_TAG, _BT_COMP_LOG_COMP_PREFIX _fmt, \
49 bt_component_class_get_name( \
50 bt_self_component_class_as_component_class( \
51 _self_comp_class)), ##__VA_ARGS__)
53 #define BT_COMP_LOG_CUR_LVL(_lvl, _cur_lvl, _self_comp, _fmt, ...) \
54 BT_LOG_WRITE_CUR_LVL((_lvl), (_cur_lvl), BT_LOG_TAG, \
55 _BT_COMP_LOG_COMP_PREFIX _fmt, \
57 bt_component_get_name( \
58 bt_self_component_as_component(_self_comp)) : \
59 _BT_COMP_LOG_COMP_NA_STR, \
62 #define BT_COMP_LOG_ERRNO(_lvl, _self_comp, _msg, _fmt, ...) \
63 BT_LOG_WRITE_ERRNO((_lvl), BT_LOG_TAG, _msg, \
64 _BT_COMP_LOG_COMP_PREFIX _fmt, \
66 bt_component_get_name( \
67 bt_self_component_as_component(_self_comp)) : \
68 _BT_COMP_LOG_COMP_NA_STR, \
71 #define BT_COMP_LOG_ERRNO_CUR_LVL(_lvl, _cur_lvl, _self_comp, _msg, _fmt, ...) \
72 BT_LOG_WRITE_ERRNO_CUR_LVL((_lvl), (_cur_lvl), BT_LOG_TAG, _msg, \
73 _BT_COMP_LOG_COMP_PREFIX _fmt, \
75 bt_component_get_name( \
76 bt_self_component_as_component(_self_comp)) : \
77 _BT_COMP_LOG_COMP_NA_STR, \
80 #define BT_COMP_LOG_MEM(_lvl, _self_comp, _data_ptr, _data_sz, _fmt, ...) \
81 BT_LOG_WRITE_MEM((_lvl), BT_LOG_TAG, (_data_ptr), (_data_sz), \
82 _BT_COMP_LOG_COMP_PREFIX _fmt, \
84 bt_component_get_name( \
85 bt_self_component_as_component(_self_comp)) : \
86 _BT_COMP_LOG_COMP_NA_STR, \
89 /* Specific per-level logging macros; they use `BT_COMP_LOG_SELF_COMP` */
90 #define BT_COMP_LOGF(_fmt, ...) \
91 BT_COMP_LOG(BT_LOG_FATAL, (BT_COMP_LOG_SELF_COMP), _fmt, ##__VA_ARGS__)
92 #define BT_COMP_LOGE(_fmt, ...) \
93 BT_COMP_LOG(BT_LOG_ERROR, (BT_COMP_LOG_SELF_COMP), _fmt, ##__VA_ARGS__)
94 #define BT_COMP_LOGW(_fmt, ...) \
95 BT_COMP_LOG(BT_LOG_WARNING, (BT_COMP_LOG_SELF_COMP), _fmt, ##__VA_ARGS__)
96 #define BT_COMP_LOGI(_fmt, ...) \
97 BT_COMP_LOG(BT_LOG_INFO, (BT_COMP_LOG_SELF_COMP), _fmt, ##__VA_ARGS__)
98 #define BT_COMP_LOGD(_fmt, ...) \
99 BT_COMP_LOG(BT_LOG_DEBUG, (BT_COMP_LOG_SELF_COMP), _fmt, ##__VA_ARGS__)
100 #define BT_COMP_LOGT(_fmt, ...) \
101 BT_COMP_LOG(BT_LOG_TRACE, (BT_COMP_LOG_SELF_COMP), _fmt, ##__VA_ARGS__)
102 #define BT_COMP_LOGF_STR(_str) \
103 BT_COMP_LOG(BT_LOG_FATAL, (BT_COMP_LOG_SELF_COMP), "%s", (_str))
104 #define BT_COMP_LOGE_STR(_str) \
105 BT_COMP_LOG(BT_LOG_ERROR, (BT_COMP_LOG_SELF_COMP), "%s", (_str))
106 #define BT_COMP_LOGW_STR(_str) \
107 BT_COMP_LOG(BT_LOG_WARNING, (BT_COMP_LOG_SELF_COMP), "%s", (_str))
108 #define BT_COMP_LOGI_STR(_str) \
109 BT_COMP_LOG(BT_LOG_INFO, (BT_COMP_LOG_SELF_COMP), "%s", (_str))
110 #define BT_COMP_LOGD_STR(_str) \
111 BT_COMP_LOG(BT_LOG_DEBUG, (BT_COMP_LOG_SELF_COMP), "%s", (_str))
112 #define BT_COMP_LOGT_STR(_str) \
113 BT_COMP_LOG(BT_LOG_TRACE, (BT_COMP_LOG_SELF_COMP), "%s", (_str))
114 #define BT_COMP_LOGF_ERRNO(_msg, _fmt, ...) \
115 BT_COMP_LOG_ERRNO(BT_LOG_FATAL, (BT_COMP_LOG_SELF_COMP), _msg, _fmt, ##__VA_ARGS__)
116 #define BT_COMP_LOGE_ERRNO(_msg, _fmt, ...) \
117 BT_COMP_LOG_ERRNO(BT_LOG_ERROR, (BT_COMP_LOG_SELF_COMP), _msg, _fmt, ##__VA_ARGS__)
118 #define BT_COMP_LOGW_ERRNO(_msg, _fmt, ...) \
119 BT_COMP_LOG_ERRNO(BT_LOG_WARNING, (BT_COMP_LOG_SELF_COMP), _msg, _fmt, ##__VA_ARGS__)
120 #define BT_COMP_LOGI_ERRNO(_msg, _fmt, ...) \
121 BT_COMP_LOG_ERRNO(BT_LOG_INFO, (BT_COMP_LOG_SELF_COMP), _msg, _fmt, ##__VA_ARGS__)
122 #define BT_COMP_LOGD_ERRNO(_msg, _fmt, ...) \
123 BT_COMP_LOG_ERRNO(BT_LOG_DEBUG, (BT_COMP_LOG_SELF_COMP), _msg, _fmt, ##__VA_ARGS__)
124 #define BT_COMP_LOGT_ERRNO(_msg, _fmt, ...) \
125 BT_COMP_LOG_ERRNO(BT_LOG_TRACE, (BT_COMP_LOG_SELF_COMP), _msg, _fmt, ##__VA_ARGS__)
126 #define BT_COMP_LOGF_MEM(_data_ptr, _data_sz, _fmt, ...) \
127 BT_COMP_LOG_MEM(BT_LOG_FATAL, (BT_COMP_LOG_SELF_COMP), (_data_ptr), (_data_sz), _fmt, ##__VA_ARGS__)
128 #define BT_COMP_LOGE_MEM(_data_ptr, _data_sz, _fmt, ...) \
129 BT_COMP_LOG_MEM(BT_LOG_ERROR, (BT_COMP_LOG_SELF_COMP), (_data_ptr), (_data_sz), _fmt, ##__VA_ARGS__)
130 #define BT_COMP_LOGW_MEM(_data_ptr, _data_sz, _fmt, ...) \
131 BT_COMP_LOG_MEM(BT_LOG_WARNING, (BT_COMP_LOG_SELF_COMP), (_data_ptr), (_data_sz), _fmt, ##__VA_ARGS__)
132 #define BT_COMP_LOGI_MEM(_data_ptr, _data_sz, _fmt, ...) \
133 BT_COMP_LOG_MEM(BT_LOG_INFO, (BT_COMP_LOG_SELF_COMP), (_data_ptr), (_data_sz), _fmt, ##__VA_ARGS__)
134 #define BT_COMP_LOGD_MEM(_data_ptr, _data_sz, _fmt, ...) \
135 BT_COMP_LOG_MEM(BT_LOG_DEBUG, (BT_COMP_LOG_SELF_COMP), (_data_ptr), (_data_sz), _fmt, ##__VA_ARGS__)
136 #define BT_COMP_LOGT_MEM(_data_ptr, _data_sz, _fmt, ...) \
137 BT_COMP_LOG_MEM(BT_LOG_TRACE, (BT_COMP_LOG_SELF_COMP), (_data_ptr), (_data_sz), _fmt, ##__VA_ARGS__)
139 #define BT_COMP_LOG_SUPPORTED
141 /* Logs and appends error cause from component context. */
142 #define BT_COMP_LOG_APPEND_CAUSE(_self_comp, _lvl, _fmt, ...) \
144 BT_COMP_LOG(_lvl, _self_comp, _fmt, ##__VA_ARGS__); \
145 (void) BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_FROM_COMPONENT( \
146 _self_comp, _fmt, ##__VA_ARGS__); \
149 /* Logs error and appends error cause from component context. */
150 #define BT_COMP_LOGE_APPEND_CAUSE(_self_comp, _fmt, ...) \
151 BT_COMP_LOG_APPEND_CAUSE(_self_comp, BT_LOG_ERROR, _fmt, ##__VA_ARGS__)
154 * Logs and appends error cause from component context - the errno edition.
156 #define BT_COMP_LOG_APPEND_CAUSE_ERRNO(_self_comp, _lvl, _msg, _fmt, ...) \
158 const char *error_str = g_strerror(errno); \
159 BT_COMP_LOG(_lvl, _self_comp, _msg ": %s" _fmt, error_str, \
161 (void) BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_FROM_COMPONENT( \
162 _self_comp, _msg ": %s" _fmt, error_str, ##__VA_ARGS__); \
166 * Logs error and appends error cause from component context - the errno
169 #define BT_COMP_LOGE_APPEND_CAUSE_ERRNO(_self_comp, _fmt, ...) \
170 BT_COMP_LOG_APPEND_CAUSE_ERRNO(_self_comp, BT_LOG_ERROR, _fmt, ##__VA_ARGS__)
172 /* Logs and appends error cause from component class context. */
173 #define BT_COMP_CLASS_LOG_APPEND_CAUSE(_self_comp_class, _lvl, _fmt, ...) \
175 BT_COMP_CLASS_LOG(_lvl, _self_comp_class, _fmt, ##__VA_ARGS__); \
176 (void) BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_FROM_COMPONENT_CLASS( \
177 _self_comp_class, _fmt, ##__VA_ARGS__); \
180 /* Logs error and appends error cause from component class context. */
181 #define BT_COMP_CLASS_LOGE_APPEND_CAUSE(_self_comp_class, _fmt, ...) \
182 BT_COMP_CLASS_LOG_APPEND_CAUSE(_self_comp_class, BT_LOG_ERROR, _fmt, ##__VA_ARGS__)
185 * Logs and appends error cause from component class context - the errno
188 #define BT_COMP_CLASS_LOG_APPEND_CAUSE_ERRNO(_self_comp_class, _lvl, _msg, _fmt, ...) \
190 const char *error_str = g_strerror(errno); \
191 BT_COMP_CLASS_LOG(_lvl, _self_comp_class, _msg ": %s" _fmt, error_str, \
193 (void) BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_FROM_COMPONENT_CLASS( \
194 _self_comp_class, _msg ": %s" _fmt, error_str, ##__VA_ARGS__); \
198 * Logs error and appends error cause from component class context - the errno
201 #define BT_COMP_CLASS_LOGE_APPEND_CAUSE_ERRNO(_self_comp_class, _fmt, ...) \
202 BT_COMP_CLASS_LOG_APPEND_CAUSE_ERRNO(_self_comp_class, BT_LOG_ERROR, _fmt, \
206 * Logs error and appends error cause from component or component class context,
207 * depending on whichever is set.
209 #define BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(_self_comp, _self_comp_class, _fmt, ...) \
211 /* Only one of `_self_comp` and `_self_comp_class` must be set. */ \
212 BT_ASSERT((!!(_self_comp) != (!!_self_comp_class))); \
214 BT_COMP_LOGE_APPEND_CAUSE(_self_comp, _fmt, ##__VA_ARGS__); \
216 BT_COMP_CLASS_LOGE_APPEND_CAUSE(_self_comp_class, _fmt, ##__VA_ARGS__); \
220 #endif /* BABELTRACE_LOGGING_COMP_LOGGING_H */
This page took 0.032809 seconds and 4 git commands to generate.