1 #ifndef BABELTRACE_PLUGINS_COMP_LOGGING_H
2 #define BABELTRACE_PLUGINS_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.
30 #ifndef BT_LOG_OUTPUT_LEVEL
31 # error Please define a log level expression with BT_LOG_OUTPUT_LEVEL before including this file.
34 #ifndef BT_COMP_LOG_SELF_COMP
35 # error Please define a self component address expression with BT_COMP_LOG_SELF_COMP before including this file.
39 #include <babeltrace2/graph/self-component.h>
40 #include <babeltrace2/graph/component-const.h>
41 #include <babeltrace2/graph/component-class-const.h>
42 #include "logging/log.h"
44 #define _BT_COMP_LOG_COMP_PREFIX "[%s] "
45 #define _BT_COMP_LOG_COMP_NA_STR "N/A"
47 /* Logs with level `_lvl` for self component `_self_comp` */
48 #define BT_COMP_LOG(_lvl, _self_comp, _fmt, ...) \
49 BT_LOG_WRITE((_lvl), BT_LOG_TAG, _BT_COMP_LOG_COMP_PREFIX _fmt, \
51 bt_component_get_name( \
52 bt_self_component_as_component(_self_comp)) : \
53 _BT_COMP_LOG_COMP_NA_STR, \
56 #define BT_COMP_LOG_CUR_LVL(_lvl, _cur_lvl, _self_comp, _fmt, ...) \
57 BT_LOG_WRITE_CUR_LVL((_lvl), (_cur_lvl), BT_LOG_TAG, \
58 _BT_COMP_LOG_COMP_PREFIX _fmt, \
60 bt_component_get_name( \
61 bt_self_component_as_component(_self_comp)) : \
62 _BT_COMP_LOG_COMP_NA_STR, \
65 #define BT_COMP_LOG_ERRNO(_lvl, _self_comp, _msg, _fmt, ...) \
66 BT_LOG_WRITE_ERRNO((_lvl), BT_LOG_TAG, _msg, \
67 _BT_COMP_LOG_COMP_PREFIX _fmt, \
69 bt_component_get_name( \
70 bt_self_component_as_component(_self_comp)) : \
71 _BT_COMP_LOG_COMP_NA_STR, \
74 #define BT_COMP_LOG_ERRNO_CUR_LVL(_lvl, _cur_lvl, _self_comp, _msg, _fmt, ...) \
75 BT_LOG_WRITE_ERRNO_CUR_LVL((_lvl), (_cur_lvl), BT_LOG_TAG, _msg, \
76 _BT_COMP_LOG_COMP_PREFIX _fmt, \
78 bt_component_get_name( \
79 bt_self_component_as_component(_self_comp)) : \
80 _BT_COMP_LOG_COMP_NA_STR, \
83 #define BT_COMP_LOG_MEM(_lvl, _self_comp, _data_ptr, _data_sz, _fmt, ...) \
84 BT_LOG_WRITE_MEM((_lvl), BT_LOG_TAG, (_data_ptr), (_data_sz), \
85 _BT_COMP_LOG_COMP_PREFIX _fmt, \
87 bt_component_get_name( \
88 bt_self_component_as_component(_self_comp)) : \
89 _BT_COMP_LOG_COMP_NA_STR, \
92 /* Specific per-level logging macros; they use `BT_COMP_LOG_SELF_COMP` */
93 #define BT_COMP_LOGF(_fmt, ...) \
94 BT_COMP_LOG(BT_LOG_FATAL, (BT_COMP_LOG_SELF_COMP), _fmt, ##__VA_ARGS__)
95 #define BT_COMP_LOGE(_fmt, ...) \
96 BT_COMP_LOG(BT_LOG_ERROR, (BT_COMP_LOG_SELF_COMP), _fmt, ##__VA_ARGS__)
97 #define BT_COMP_LOGW(_fmt, ...) \
98 BT_COMP_LOG(BT_LOG_WARN, (BT_COMP_LOG_SELF_COMP), _fmt, ##__VA_ARGS__)
99 #define BT_COMP_LOGI(_fmt, ...) \
100 BT_COMP_LOG(BT_LOG_INFO, (BT_COMP_LOG_SELF_COMP), _fmt, ##__VA_ARGS__)
101 #define BT_COMP_LOGD(_fmt, ...) \
102 BT_COMP_LOG(BT_LOG_DEBUG, (BT_COMP_LOG_SELF_COMP), _fmt, ##__VA_ARGS__)
103 #define BT_COMP_LOGV(_fmt, ...) \
104 BT_COMP_LOG(BT_LOG_VERBOSE, (BT_COMP_LOG_SELF_COMP), _fmt, ##__VA_ARGS__)
105 #define BT_COMP_LOGF_STR(_str) \
106 BT_COMP_LOG(BT_LOG_FATAL, (BT_COMP_LOG_SELF_COMP), "%s", (_str))
107 #define BT_COMP_LOGE_STR(_str) \
108 BT_COMP_LOG(BT_LOG_ERROR, (BT_COMP_LOG_SELF_COMP), "%s", (_str))
109 #define BT_COMP_LOGW_STR(_str) \
110 BT_COMP_LOG(BT_LOG_WARN, (BT_COMP_LOG_SELF_COMP), "%s", (_str))
111 #define BT_COMP_LOGI_STR(_str) \
112 BT_COMP_LOG(BT_LOG_INFO, (BT_COMP_LOG_SELF_COMP), "%s", (_str))
113 #define BT_COMP_LOGD_STR(_str) \
114 BT_COMP_LOG(BT_LOG_DEBUG, (BT_COMP_LOG_SELF_COMP), "%s", (_str))
115 #define BT_COMP_LOGV_STR(_str) \
116 BT_COMP_LOG(BT_LOG_VERBOSE, (BT_COMP_LOG_SELF_COMP), "%s", (_str))
117 #define BT_COMP_LOGF_ERRNO(_msg, _fmt, ...) \
118 BT_COMP_LOG_ERRNO(BT_LOG_FATAL, (BT_COMP_LOG_SELF_COMP), _msg, _fmt, ##__VA_ARGS__)
119 #define BT_COMP_LOGE_ERRNO(_msg, _fmt, ...) \
120 BT_COMP_LOG_ERRNO(BT_LOG_ERROR, (BT_COMP_LOG_SELF_COMP), _msg, _fmt, ##__VA_ARGS__)
121 #define BT_COMP_LOGW_ERRNO(_msg, _fmt, ...) \
122 BT_COMP_LOG_ERRNO(BT_LOG_WARN, (BT_COMP_LOG_SELF_COMP), _msg, _fmt, ##__VA_ARGS__)
123 #define BT_COMP_LOGI_ERRNO(_msg, _fmt, ...) \
124 BT_COMP_LOG_ERRNO(BT_LOG_INFO, (BT_COMP_LOG_SELF_COMP), _msg, _fmt, ##__VA_ARGS__)
125 #define BT_COMP_LOGD_ERRNO(_msg, _fmt, ...) \
126 BT_COMP_LOG_ERRNO(BT_LOG_DEBUG, (BT_COMP_LOG_SELF_COMP), _msg, _fmt, ##__VA_ARGS__)
127 #define BT_COMP_LOGV_ERRNO(_msg, _fmt, ...) \
128 BT_COMP_LOG_ERRNO(BT_LOG_VERBOSE, (BT_COMP_LOG_SELF_COMP), _msg, _fmt, ##__VA_ARGS__)
129 #define BT_COMP_LOGF_MEM(_data_ptr, _data_sz, _fmt, ...) \
130 BT_COMP_LOG_MEM(BT_LOG_FATAL, (BT_COMP_LOG_SELF_COMP), (_data_ptr), (_data_sz), _fmt, ##__VA_ARGS__)
131 #define BT_COMP_LOGE_MEM(_data_ptr, _data_sz, _fmt, ...) \
132 BT_COMP_LOG_MEM(BT_LOG_ERROR, (BT_COMP_LOG_SELF_COMP), (_data_ptr), (_data_sz), _fmt, ##__VA_ARGS__)
133 #define BT_COMP_LOGW_MEM(_data_ptr, _data_sz, _fmt, ...) \
134 BT_COMP_LOG_MEM(BT_LOG_WARN, (BT_COMP_LOG_SELF_COMP), (_data_ptr), (_data_sz), _fmt, ##__VA_ARGS__)
135 #define BT_COMP_LOGI_MEM(_data_ptr, _data_sz, _fmt, ...) \
136 BT_COMP_LOG_MEM(BT_LOG_INFO, (BT_COMP_LOG_SELF_COMP), (_data_ptr), (_data_sz), _fmt, ##__VA_ARGS__)
137 #define BT_COMP_LOGD_MEM(_data_ptr, _data_sz, _fmt, ...) \
138 BT_COMP_LOG_MEM(BT_LOG_DEBUG, (BT_COMP_LOG_SELF_COMP), (_data_ptr), (_data_sz), _fmt, ##__VA_ARGS__)
139 #define BT_COMP_LOGV_MEM(_data_ptr, _data_sz, _fmt, ...) \
140 BT_COMP_LOG_MEM(BT_LOG_VERBOSE, (BT_COMP_LOG_SELF_COMP), (_data_ptr), (_data_sz), _fmt, ##__VA_ARGS__)
142 #endif /* BABELTRACE_PLUGINS_COMP_LOGGING_H */
This page took 0.032637 seconds and 4 git commands to generate.