Commit | Line | Data |
---|---|---|
beb0fb75 PP |
1 | #ifndef BABELTRACE_LIB_LOGGING_INTERNAL_H |
2 | #define BABELTRACE_LIB_LOGGING_INTERNAL_H | |
3 | ||
4 | /* | |
5 | * Copyright 2017 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 | #include <babeltrace/babeltrace-internal.h> | |
476ef981 | 27 | #include <stdarg.h> |
beb0fb75 PP |
28 | |
29 | #define BT_LOG_OUTPUT_LEVEL bt_lib_log_level | |
30 | ||
31 | #include <babeltrace/logging-internal.h> | |
32 | ||
61d6f9b1 | 33 | extern |
beb0fb75 PP |
34 | int bt_lib_log_level; |
35 | ||
3dca2276 PP |
36 | #define BT_LIB_LOG(_lvl, _fmt, ...) \ |
37 | do { \ | |
38 | if (BT_LOG_ON(_lvl)) { \ | |
39 | bt_lib_log(_BT_LOG_SRCLOC_FUNCTION, __FILE__, \ | |
40 | __LINE__, _lvl, _BT_LOG_TAG, \ | |
41 | (_fmt), ##__VA_ARGS__); \ | |
42 | } \ | |
43 | } while (0) | |
44 | ||
476ef981 PP |
45 | /* |
46 | * The six macros below are logging statements which are specialized | |
47 | * for the Babeltrace library. | |
48 | * | |
49 | * `_fmt` is a typical printf()-style format string, with the following | |
50 | * limitations: | |
51 | * | |
52 | * * The `*` width specifier is not accepted. | |
53 | * * The `*` precision specifier is not accepted. | |
54 | * * The `j` and `t` length modifiers are not accepted. | |
55 | * * The `n` format specifier is not accepted. | |
56 | * * The format specifiers defined in <inttypes.h> are not accepted | |
57 | * except for `PRId64`, `PRIu64`, `PRIx64`, `PRIX64`, `PRIo64`, and | |
58 | * `PRIi64`. | |
59 | * | |
60 | * The Babeltrace extension conversion specifier is accepted. Its syntax | |
61 | * is: | |
62 | * | |
63 | * 1. Introductory `%!` sequence. | |
64 | * | |
65 | * 2. Optional: `[` followed by a custom prefix for the printed fields | |
66 | * of this specifier, followed by `]`. The standard form is to end | |
67 | * this prefix with `-` so that, for example, with the prefix | |
68 | * `prefix-`, the complete field name is `prefix-addr`. | |
69 | * | |
70 | * 3. Optional: `+` to print extended fields. This depends on the | |
71 | * provided format specifier. | |
72 | * | |
3dca2276 PP |
73 | * 4. Objet category: `w` for CTF writer objects, `_` for common |
74 | * objects, or nothing for default objects (includes CTF IR). | |
75 | * | |
76 | * 5. Format specifier (see below). | |
476ef981 PP |
77 | * |
78 | * The available format specifiers are: | |
79 | * | |
3dca2276 PP |
80 | * Default category: |
81 | * `r`: | |
82 | * Reference count information. The parameter is any Babeltrace | |
83 | * object. | |
84 | * | |
85 | * `F`: | |
86 | * CTF IR field type. The parameter type is `struct bt_field_type *`. | |
87 | * | |
88 | * `f`: | |
89 | * CTF IR field. The parameter type is `struct bt_field *`. | |
90 | * | |
91 | * `P`: | |
92 | * Field path. The parameter type is `struct bt_field_path *`. | |
93 | * | |
94 | * `E`: | |
95 | * CTF IR event class. The parameter type is `struct bt_event_class *`. | |
96 | * | |
97 | * `e`: | |
98 | * CTF IR event. The parameter type is `struct bt_event *`. | |
99 | * | |
100 | * `S`: | |
101 | * CTF IR stream class. The parameter type is `struct bt_stream_class *`. | |
102 | * | |
103 | * `s`: | |
104 | * CTF IR stream. The parameter type is `struct bt_stream *`. | |
105 | * | |
106 | * `a`: | |
107 | * Packet. The parameter type is `struct bt_packet *`. | |
476ef981 | 108 | * |
3dca2276 PP |
109 | * `t`: |
110 | * CTF IR trace. The parameter type is `struct bt_trace *`. | |
476ef981 | 111 | * |
3dca2276 PP |
112 | * `K`: |
113 | * Clock class. The parameter type is `struct bt_clock_class *`. | |
476ef981 | 114 | * |
3dca2276 PP |
115 | * `k`: |
116 | * Clock value. The parameter type is `struct bt_clock_value *`. | |
476ef981 | 117 | * |
3dca2276 PP |
118 | * `v`: |
119 | * Value. The parameter type is `struct bt_value *`. | |
476ef981 | 120 | * |
3dca2276 PP |
121 | * `n`: |
122 | * Notification. The parameter type is `struct bt_notification *`. | |
476ef981 | 123 | * |
3dca2276 PP |
124 | * `i`: |
125 | * Notification iterator. The parameter type is | |
126 | * `struct bt_notification_iterator *`. | |
476ef981 | 127 | * |
3dca2276 PP |
128 | * `C`: |
129 | * Component class. The parameter type is `struct bt_component_class *`. | |
476ef981 | 130 | * |
3dca2276 PP |
131 | * `c`: |
132 | * Component. The parameter type is `struct bt_component *`. | |
476ef981 | 133 | * |
3dca2276 PP |
134 | * `p`: |
135 | * Port. The parameter type is `struct bt_port *`. | |
476ef981 | 136 | * |
3dca2276 PP |
137 | * `x`: |
138 | * Connection. The parameter type is `struct bt_connection *`. | |
476ef981 | 139 | * |
3dca2276 PP |
140 | * `g`: |
141 | * Graph. The parameter type is `struct bt_graph *`. | |
476ef981 | 142 | * |
3dca2276 PP |
143 | * `u`: |
144 | * Plugin. The parameter type is `struct bt_plugin *`. | |
476ef981 | 145 | * |
3dca2276 PP |
146 | * CTF writer category: |
147 | * `F`: | |
148 | * CTF writer field type. The parameter type is `struct bt_field_type *`. | |
476ef981 | 149 | * |
3dca2276 PP |
150 | * `f`: |
151 | * CTF writer field. The parameter type is `struct bt_field *`. | |
476ef981 | 152 | * |
3dca2276 PP |
153 | * `E`: |
154 | * CTF writer event class. The parameter type is | |
155 | * `struct bt_event_class *`. | |
476ef981 | 156 | * |
3dca2276 PP |
157 | * `e`: |
158 | * CTF writer event. The parameter type is `struct bt_event *`. | |
476ef981 | 159 | * |
3dca2276 PP |
160 | * `S`: |
161 | * CTF writer stream class. The parameter type is | |
162 | * `struct bt_stream_class *`. | |
476ef981 | 163 | * |
3dca2276 PP |
164 | * `s`: |
165 | * CTF writer stream. The parameter type is `struct bt_stream *`. | |
476ef981 | 166 | * |
3dca2276 PP |
167 | * `t`: |
168 | * CTF writer trace. The parameter type is `struct bt_trace *`. | |
476ef981 | 169 | * |
3dca2276 PP |
170 | * `w`: |
171 | * CTF writer. The parameter type is `struct bt_ctf_writer *`. | |
476ef981 | 172 | * |
3dca2276 PP |
173 | * Common category: |
174 | * `F`: | |
175 | * Common field type. The parameter type is `struct bt_field_type *`. | |
176 | * | |
177 | * `f`: | |
178 | * Common field. The parameter type is `struct bt_field *`. | |
179 | * | |
180 | * `E`: | |
181 | * Common event class. The parameter type is | |
182 | * `struct bt_event_class *`. | |
183 | * | |
184 | * `e`: | |
185 | * Common event. The parameter type is `struct bt_event *`. | |
186 | * | |
187 | * `S`: | |
188 | * Common stream class. The parameter type is | |
189 | * `struct bt_stream_class *`. | |
190 | * | |
191 | * `s`: | |
192 | * Common stream. The parameter type is `struct bt_stream *`. | |
193 | * | |
194 | * `t`: | |
195 | * Common trace. The parameter type is `struct bt_trace *`. | |
196 | * | |
197 | * Conversion specifier examples: | |
198 | * | |
199 | * %!f | |
200 | * %![my-event-]+e | |
201 | * %!_t | |
202 | * %![ctf-writer-ec-]wE | |
203 | * %!+_F | |
476ef981 PP |
204 | * |
205 | * The string `, ` is printed between individual fields, but not after | |
206 | * the last one. Therefore you must put this separator in the format | |
207 | * string between two Babeltrace objects, e.g.: | |
208 | * | |
209 | * BT_LIB_LOGW("Message: count=%u, %!E, %!+C", count, event_class, | |
210 | * clock_class); | |
211 | * | |
212 | * Example with a custom prefix: | |
213 | * | |
214 | * BT_LIB_LOGI("Some message: %![ec-a-]e, %![ec-b-]+e", ec_a, ec_b); | |
215 | * | |
216 | * It is safe to pass NULL as any Babeltrace object parameter: the | |
217 | * macros only print its null address. | |
218 | */ | |
476ef981 PP |
219 | #define BT_LIB_LOGF(_fmt, ...) BT_LIB_LOG(BT_LOG_FATAL, _fmt, ##__VA_ARGS__) |
220 | #define BT_LIB_LOGE(_fmt, ...) BT_LIB_LOG(BT_LOG_ERROR, _fmt, ##__VA_ARGS__) | |
221 | #define BT_LIB_LOGW(_fmt, ...) BT_LIB_LOG(BT_LOG_WARN, _fmt, ##__VA_ARGS__) | |
222 | #define BT_LIB_LOGI(_fmt, ...) BT_LIB_LOG(BT_LOG_INFO, _fmt, ##__VA_ARGS__) | |
223 | #define BT_LIB_LOGD(_fmt, ...) BT_LIB_LOG(BT_LOG_DEBUG, _fmt, ##__VA_ARGS__) | |
224 | #define BT_LIB_LOGV(_fmt, ...) BT_LIB_LOG(BT_LOG_VERBOSE, _fmt, ##__VA_ARGS__) | |
225 | ||
226 | /* | |
227 | * Log statement, specialized for the Babeltrace library. | |
228 | * | |
229 | * Use one of the BT_LIB_LOGF*() macros above instead of calling this | |
230 | * function directly. | |
231 | */ | |
232 | BT_HIDDEN | |
233 | void bt_lib_log(const char *func, const char *file, unsigned line, | |
234 | int lvl, const char *tag, const char *fmt, ...); | |
235 | ||
beb0fb75 | 236 | #endif /* BABELTRACE_LIB_LOGGING_INTERNAL_H */ |