22e9bdaeaa52262333d8514071d23bdbc03c92d8
[babeltrace.git] / src / logging / comp-logging.h
1 #ifndef BABELTRACE_LOGGING_COMP_LOGGING_H
2 #define BABELTRACE_LOGGING_COMP_LOGGING_H
3
4 /*
5 * Copyright 2019 Philippe Proulx <pproulx@efficios.com>
6 *
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:
13 *
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
16 *
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
23 * SOFTWARE.
24 */
25
26 #ifndef BT_LOG_TAG
27 # error Please define a tag with BT_LOG_TAG before including this file.
28 #endif
29
30 #include <stdlib.h>
31 #include <babeltrace2/babeltrace.h>
32 #include "logging/log.h"
33
34 #define _BT_COMP_LOG_COMP_PREFIX "[%s] "
35 #define _BT_COMP_LOG_COMP_NA_STR "N/A"
36
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, \
40 (_self_comp) ? \
41 bt_component_get_name( \
42 bt_self_component_as_component(_self_comp)) : \
43 _BT_COMP_LOG_COMP_NA_STR, \
44 ##__VA_ARGS__)
45
46 #define BT_COMP_LOG_CUR_LVL(_lvl, _cur_lvl, _self_comp, _fmt, ...) \
47 BT_LOG_WRITE_CUR_LVL((_lvl), (_cur_lvl), BT_LOG_TAG, \
48 _BT_COMP_LOG_COMP_PREFIX _fmt, \
49 (_self_comp) ? \
50 bt_component_get_name( \
51 bt_self_component_as_component(_self_comp)) : \
52 _BT_COMP_LOG_COMP_NA_STR, \
53 ##__VA_ARGS__)
54
55 #define BT_COMP_LOG_ERRNO(_lvl, _self_comp, _msg, _fmt, ...) \
56 BT_LOG_WRITE_ERRNO((_lvl), BT_LOG_TAG, _msg, \
57 _BT_COMP_LOG_COMP_PREFIX _fmt, \
58 (_self_comp) ? \
59 bt_component_get_name( \
60 bt_self_component_as_component(_self_comp)) : \
61 _BT_COMP_LOG_COMP_NA_STR, \
62 ##__VA_ARGS__)
63
64 #define BT_COMP_LOG_ERRNO_CUR_LVL(_lvl, _cur_lvl, _self_comp, _msg, _fmt, ...) \
65 BT_LOG_WRITE_ERRNO_CUR_LVL((_lvl), (_cur_lvl), BT_LOG_TAG, _msg, \
66 _BT_COMP_LOG_COMP_PREFIX _fmt, \
67 (_self_comp) ? \
68 bt_component_get_name( \
69 bt_self_component_as_component(_self_comp)) : \
70 _BT_COMP_LOG_COMP_NA_STR, \
71 ##__VA_ARGS__)
72
73 #define BT_COMP_LOG_MEM(_lvl, _self_comp, _data_ptr, _data_sz, _fmt, ...) \
74 BT_LOG_WRITE_MEM((_lvl), BT_LOG_TAG, (_data_ptr), (_data_sz), \
75 _BT_COMP_LOG_COMP_PREFIX _fmt, \
76 (_self_comp) ? \
77 bt_component_get_name( \
78 bt_self_component_as_component(_self_comp)) : \
79 _BT_COMP_LOG_COMP_NA_STR, \
80 ##__VA_ARGS__)
81
82 /* Specific per-level logging macros; they use `BT_COMP_LOG_SELF_COMP` */
83 #define BT_COMP_LOGF(_fmt, ...) \
84 BT_COMP_LOG(BT_LOG_FATAL, (BT_COMP_LOG_SELF_COMP), _fmt, ##__VA_ARGS__)
85 #define BT_COMP_LOGE(_fmt, ...) \
86 BT_COMP_LOG(BT_LOG_ERROR, (BT_COMP_LOG_SELF_COMP), _fmt, ##__VA_ARGS__)
87 #define BT_COMP_LOGW(_fmt, ...) \
88 BT_COMP_LOG(BT_LOG_WARNING, (BT_COMP_LOG_SELF_COMP), _fmt, ##__VA_ARGS__)
89 #define BT_COMP_LOGI(_fmt, ...) \
90 BT_COMP_LOG(BT_LOG_INFO, (BT_COMP_LOG_SELF_COMP), _fmt, ##__VA_ARGS__)
91 #define BT_COMP_LOGD(_fmt, ...) \
92 BT_COMP_LOG(BT_LOG_DEBUG, (BT_COMP_LOG_SELF_COMP), _fmt, ##__VA_ARGS__)
93 #define BT_COMP_LOGT(_fmt, ...) \
94 BT_COMP_LOG(BT_LOG_TRACE, (BT_COMP_LOG_SELF_COMP), _fmt, ##__VA_ARGS__)
95 #define BT_COMP_LOGF_STR(_str) \
96 BT_COMP_LOG(BT_LOG_FATAL, (BT_COMP_LOG_SELF_COMP), "%s", (_str))
97 #define BT_COMP_LOGE_STR(_str) \
98 BT_COMP_LOG(BT_LOG_ERROR, (BT_COMP_LOG_SELF_COMP), "%s", (_str))
99 #define BT_COMP_LOGW_STR(_str) \
100 BT_COMP_LOG(BT_LOG_WARNING, (BT_COMP_LOG_SELF_COMP), "%s", (_str))
101 #define BT_COMP_LOGI_STR(_str) \
102 BT_COMP_LOG(BT_LOG_INFO, (BT_COMP_LOG_SELF_COMP), "%s", (_str))
103 #define BT_COMP_LOGD_STR(_str) \
104 BT_COMP_LOG(BT_LOG_DEBUG, (BT_COMP_LOG_SELF_COMP), "%s", (_str))
105 #define BT_COMP_LOGT_STR(_str) \
106 BT_COMP_LOG(BT_LOG_TRACE, (BT_COMP_LOG_SELF_COMP), "%s", (_str))
107 #define BT_COMP_LOGF_ERRNO(_msg, _fmt, ...) \
108 BT_COMP_LOG_ERRNO(BT_LOG_FATAL, (BT_COMP_LOG_SELF_COMP), _msg, _fmt, ##__VA_ARGS__)
109 #define BT_COMP_LOGE_ERRNO(_msg, _fmt, ...) \
110 BT_COMP_LOG_ERRNO(BT_LOG_ERROR, (BT_COMP_LOG_SELF_COMP), _msg, _fmt, ##__VA_ARGS__)
111 #define BT_COMP_LOGW_ERRNO(_msg, _fmt, ...) \
112 BT_COMP_LOG_ERRNO(BT_LOG_WARNING, (BT_COMP_LOG_SELF_COMP), _msg, _fmt, ##__VA_ARGS__)
113 #define BT_COMP_LOGI_ERRNO(_msg, _fmt, ...) \
114 BT_COMP_LOG_ERRNO(BT_LOG_INFO, (BT_COMP_LOG_SELF_COMP), _msg, _fmt, ##__VA_ARGS__)
115 #define BT_COMP_LOGD_ERRNO(_msg, _fmt, ...) \
116 BT_COMP_LOG_ERRNO(BT_LOG_DEBUG, (BT_COMP_LOG_SELF_COMP), _msg, _fmt, ##__VA_ARGS__)
117 #define BT_COMP_LOGT_ERRNO(_msg, _fmt, ...) \
118 BT_COMP_LOG_ERRNO(BT_LOG_TRACE, (BT_COMP_LOG_SELF_COMP), _msg, _fmt, ##__VA_ARGS__)
119 #define BT_COMP_LOGF_MEM(_data_ptr, _data_sz, _fmt, ...) \
120 BT_COMP_LOG_MEM(BT_LOG_FATAL, (BT_COMP_LOG_SELF_COMP), (_data_ptr), (_data_sz), _fmt, ##__VA_ARGS__)
121 #define BT_COMP_LOGE_MEM(_data_ptr, _data_sz, _fmt, ...) \
122 BT_COMP_LOG_MEM(BT_LOG_ERROR, (BT_COMP_LOG_SELF_COMP), (_data_ptr), (_data_sz), _fmt, ##__VA_ARGS__)
123 #define BT_COMP_LOGW_MEM(_data_ptr, _data_sz, _fmt, ...) \
124 BT_COMP_LOG_MEM(BT_LOG_WARNING, (BT_COMP_LOG_SELF_COMP), (_data_ptr), (_data_sz), _fmt, ##__VA_ARGS__)
125 #define BT_COMP_LOGI_MEM(_data_ptr, _data_sz, _fmt, ...) \
126 BT_COMP_LOG_MEM(BT_LOG_INFO, (BT_COMP_LOG_SELF_COMP), (_data_ptr), (_data_sz), _fmt, ##__VA_ARGS__)
127 #define BT_COMP_LOGD_MEM(_data_ptr, _data_sz, _fmt, ...) \
128 BT_COMP_LOG_MEM(BT_LOG_DEBUG, (BT_COMP_LOG_SELF_COMP), (_data_ptr), (_data_sz), _fmt, ##__VA_ARGS__)
129 #define BT_COMP_LOGT_MEM(_data_ptr, _data_sz, _fmt, ...) \
130 BT_COMP_LOG_MEM(BT_LOG_TRACE, (BT_COMP_LOG_SELF_COMP), (_data_ptr), (_data_sz), _fmt, ##__VA_ARGS__)
131
132 #define BT_COMP_LOG_SUPPORTED
133
134 #endif /* BABELTRACE_LOGGING_COMP_LOGGING_H */
This page took 0.033895 seconds and 3 git commands to generate.