lib: Add functions to borrow specialized component classes from specialized components
[babeltrace.git] / include / babeltrace / lib-logging-internal.h
CommitLineData
beb0fb75
PP
1#ifndef BABELTRACE_LIB_LOGGING_INTERNAL_H
2#define BABELTRACE_LIB_LOGGING_INTERNAL_H
3
4/*
e2f7325d 5 * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com>
beb0fb75
PP
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 28
44c440bc
PP
29#ifndef BT_LOG_TAG
30# error Please define a tag with BT_LOG_TAG before including this file.
31#endif
32
beb0fb75
PP
33#define BT_LOG_OUTPUT_LEVEL bt_lib_log_level
34
35#include <babeltrace/logging-internal.h>
36
61d6f9b1 37extern
beb0fb75
PP
38int bt_lib_log_level;
39
3dca2276
PP
40#define BT_LIB_LOG(_lvl, _fmt, ...) \
41 do { \
42 if (BT_LOG_ON(_lvl)) { \
43 bt_lib_log(_BT_LOG_SRCLOC_FUNCTION, __FILE__, \
44 __LINE__, _lvl, _BT_LOG_TAG, \
45 (_fmt), ##__VA_ARGS__); \
46 } \
47 } while (0)
48
476ef981
PP
49/*
50 * The six macros below are logging statements which are specialized
51 * for the Babeltrace library.
52 *
53 * `_fmt` is a typical printf()-style format string, with the following
54 * limitations:
55 *
56 * * The `*` width specifier is not accepted.
57 * * The `*` precision specifier is not accepted.
58 * * The `j` and `t` length modifiers are not accepted.
59 * * The `n` format specifier is not accepted.
60 * * The format specifiers defined in <inttypes.h> are not accepted
61 * except for `PRId64`, `PRIu64`, `PRIx64`, `PRIX64`, `PRIo64`, and
62 * `PRIi64`.
63 *
64 * The Babeltrace extension conversion specifier is accepted. Its syntax
44c440bc 65 * is either `%!u` to format a UUID (`bt_uuid` type) or:
476ef981
PP
66 *
67 * 1. Introductory `%!` sequence.
68 *
69 * 2. Optional: `[` followed by a custom prefix for the printed fields
70 * of this specifier, followed by `]`. The standard form is to end
71 * this prefix with `-` so that, for example, with the prefix
72 * `prefix-`, the complete field name is `prefix-addr`.
73 *
74 * 3. Optional: `+` to print extended fields. This depends on the
75 * provided format specifier.
76 *
cb6f1f7d 77 * 4. Format specifier (see below).
476ef981
PP
78 *
79 * The available format specifiers are:
80 *
3dca2276 81 * `F`:
5cd6d0e5 82 * Trace IR field class. The parameter type is
9dbb4d38 83 * `struct bt_field_class *`.
3dca2276
PP
84 *
85 * `f`:
56e18c4c 86 * Trace IR field. The parameter type is `struct bt_field *`.
3dca2276
PP
87 *
88 * `P`:
89 * Field path. The parameter type is `struct bt_field_path *`.
90 *
91 * `E`:
5cd6d0e5
PP
92 * Trace IR event class. The parameter type is
93 * `struct bt_event_class *`.
3dca2276
PP
94 *
95 * `e`:
56e18c4c 96 * Trace IR event. The parameter type is `struct bt_event *`.
3dca2276
PP
97 *
98 * `S`:
5cd6d0e5
PP
99 * Trace IR stream class. The parameter type is
100 * `struct bt_stream_class *`.
3dca2276
PP
101 *
102 * `s`:
56e18c4c 103 * Trace IR stream. The parameter type is `struct bt_stream *`.
3dca2276
PP
104 *
105 * `a`:
106 * Packet. The parameter type is `struct bt_packet *`.
476ef981 107 *
862ca4ed
PP
108 * `T`:
109 * Trace IR trace class. The parameter type is `struct bt_trace_class *`.
110 *
3dca2276 111 * `t`:
56e18c4c 112 * Trace IR trace. The parameter type is `struct bt_trace *`.
476ef981 113 *
3dca2276
PP
114 * `K`:
115 * Clock class. The parameter type is `struct bt_clock_class *`.
476ef981 116 *
3dca2276 117 * `k`:
605e1019 118 * Clock snapshot. The parameter type is `struct bt_clock_snapshot *`.
476ef981 119 *
3dca2276
PP
120 * `v`:
121 * Value. The parameter type is `struct bt_value *`.
476ef981 122 *
3dca2276 123 * `n`:
d6e69534 124 * Message. The parameter type is `struct bt_message *`.
476ef981 125 *
3dca2276 126 * `i`:
d6e69534
PP
127 * Message iterator. The parameter type is
128 * `struct bt_message_iterator *`.
476ef981 129 *
3dca2276 130 * `C`:
9dbb4d38
PP
131 * Component class. The parameter type is
132 * `struct bt_component_class *`.
476ef981 133 *
3dca2276
PP
134 * `c`:
135 * Component. The parameter type is `struct bt_component *`.
476ef981 136 *
3dca2276
PP
137 * `p`:
138 * Port. The parameter type is `struct bt_port *`.
476ef981 139 *
3dca2276
PP
140 * `x`:
141 * Connection. The parameter type is `struct bt_connection *`.
476ef981 142 *
3dca2276
PP
143 * `g`:
144 * Graph. The parameter type is `struct bt_graph *`.
476ef981 145 *
44c440bc 146 * `l`:
92fed4e1 147 * Plugin. The parameter type is `const struct bt_plugin *`.
476ef981 148 *
312c056a
PP
149 * `o`:
150 * Object pool. The parameter type is `struct bt_object_pool *`.
151 *
44c440bc
PP
152 * `O`:
153 * Object. The parameter type is `struct bt_object *`.
154 *
3dca2276
PP
155 * Conversion specifier examples:
156 *
157 * %!f
158 * %![my-event-]+e
cb6f1f7d
PP
159 * %!t
160 * %!+F
476ef981
PP
161 *
162 * The string `, ` is printed between individual fields, but not after
163 * the last one. Therefore you must put this separator in the format
9dbb4d38 164 * string between two conversion specifiers, e.g.:
476ef981 165 *
44c440bc 166 * BT_LIB_LOGW("Message: count=%u, %!E, %!+K", count, event_class,
476ef981
PP
167 * clock_class);
168 *
169 * Example with a custom prefix:
170 *
171 * BT_LIB_LOGI("Some message: %![ec-a-]e, %![ec-b-]+e", ec_a, ec_b);
172 *
173 * It is safe to pass NULL as any Babeltrace object parameter: the
174 * macros only print its null address.
175 */
476ef981
PP
176#define BT_LIB_LOGF(_fmt, ...) BT_LIB_LOG(BT_LOG_FATAL, _fmt, ##__VA_ARGS__)
177#define BT_LIB_LOGE(_fmt, ...) BT_LIB_LOG(BT_LOG_ERROR, _fmt, ##__VA_ARGS__)
178#define BT_LIB_LOGW(_fmt, ...) BT_LIB_LOG(BT_LOG_WARN, _fmt, ##__VA_ARGS__)
179#define BT_LIB_LOGI(_fmt, ...) BT_LIB_LOG(BT_LOG_INFO, _fmt, ##__VA_ARGS__)
180#define BT_LIB_LOGD(_fmt, ...) BT_LIB_LOG(BT_LOG_DEBUG, _fmt, ##__VA_ARGS__)
181#define BT_LIB_LOGV(_fmt, ...) BT_LIB_LOG(BT_LOG_VERBOSE, _fmt, ##__VA_ARGS__)
182
183/*
184 * Log statement, specialized for the Babeltrace library.
185 *
186 * Use one of the BT_LIB_LOGF*() macros above instead of calling this
187 * function directly.
188 */
88b3fc9c 189
476ef981
PP
190void bt_lib_log(const char *func, const char *file, unsigned line,
191 int lvl, const char *tag, const char *fmt, ...);
192
beb0fb75 193#endif /* BABELTRACE_LIB_LOGGING_INTERNAL_H */
This page took 0.047168 seconds and 4 git commands to generate.