lib: metadata: transform fast path precond. checks to BT_ASSERT_PRE()
[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/*
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 33extern
beb0fb75
PP
34int bt_lib_log_level;
35
476ef981
PP
36/*
37 * The six macros below are logging statements which are specialized
38 * for the Babeltrace library.
39 *
40 * `_fmt` is a typical printf()-style format string, with the following
41 * limitations:
42 *
43 * * The `*` width specifier is not accepted.
44 * * The `*` precision specifier is not accepted.
45 * * The `j` and `t` length modifiers are not accepted.
46 * * The `n` format specifier is not accepted.
47 * * The format specifiers defined in <inttypes.h> are not accepted
48 * except for `PRId64`, `PRIu64`, `PRIx64`, `PRIX64`, `PRIo64`, and
49 * `PRIi64`.
50 *
51 * The Babeltrace extension conversion specifier is accepted. Its syntax
52 * is:
53 *
54 * 1. Introductory `%!` sequence.
55 *
56 * 2. Optional: `[` followed by a custom prefix for the printed fields
57 * of this specifier, followed by `]`. The standard form is to end
58 * this prefix with `-` so that, for example, with the prefix
59 * `prefix-`, the complete field name is `prefix-addr`.
60 *
61 * 3. Optional: `+` to print extended fields. This depends on the
62 * provided format specifier.
63 *
64 * 4. Format specifier.
65 *
66 * The available format specifiers are:
67 *
68 * `r`:
69 * Reference count information. The parameter is any Babeltrace
70 * object.
71 *
72 * `F`:
73 * Field type. The parameter type is `struct bt_field_type *`.
74 *
75 * `f`:
76 * Field. The parameter type is `struct bt_field *`.
77 *
78 * `P`:
79 * Field path. The parameter type is `struct bt_field_path *`.
80 *
81 * `E`:
82 * Event class. The parameter type is `struct bt_event_class *`.
83 *
84 * `e`:
85 * Event. The parameter type is `struct bt_event *`.
86 *
87 * `S`:
88 * Stream class. The parameter type is `struct bt_stream_class *`.
89 *
90 * `s`:
91 * Stream. The parameter type is `struct bt_stream *`.
92 *
93 * `a`:
94 * Packet. The parameter type is `struct bt_packet *`.
95 *
96 * `t`:
97 * Trace. The parameter type is `struct bt_trace *`.
98 *
99 * `K`:
100 * Clock class. The parameter type is `struct bt_clock_class *`.
101 *
102 * `k`:
103 * Clock value. The parameter type is `struct bt_clock_value *`.
104 *
105 * `v`:
106 * Value. The parameter type is `struct bt_value *`.
107 *
108 * `n`:
109 * Notification. The parameter type is `struct bt_notification *`.
110 *
111 * `i`:
112 * Notification iterator. The parameter type is
113 * `struct bt_notification_iterator *`.
114 *
115 * `C`:
116 * Component class. The parameter type is `struct bt_component_class *`.
117 *
118 * `c`:
119 * Component. The parameter type is `struct bt_component *`.
120 *
121 * `p`:
122 * Port. The parameter type is `struct bt_port *`.
123 *
124 * `x`:
125 * Connection. The parameter type is `struct bt_connection *`.
126 *
127 * `g`:
128 * Graph. The parameter type is `struct bt_graph *`.
129 *
130 * `u`:
131 * Plugin. The parameter type is `struct bt_plugin *`.
132 *
133 * `w`:
134 * CTF writer. The parameter type is `struct bt_ctf_writer *`.
135 *
136 * The string `, ` is printed between individual fields, but not after
137 * the last one. Therefore you must put this separator in the format
138 * string between two Babeltrace objects, e.g.:
139 *
140 * BT_LIB_LOGW("Message: count=%u, %!E, %!+C", count, event_class,
141 * clock_class);
142 *
143 * Example with a custom prefix:
144 *
145 * BT_LIB_LOGI("Some message: %![ec-a-]e, %![ec-b-]+e", ec_a, ec_b);
146 *
147 * It is safe to pass NULL as any Babeltrace object parameter: the
148 * macros only print its null address.
149 */
150#define BT_LIB_LOG(_lvl, _fmt, ...) \
151 do { \
152 if (BT_LOG_ON(_lvl)) { \
153 bt_lib_log(_BT_LOG_SRCLOC_FUNCTION, __FILE__, \
154 __LINE__, _lvl, _BT_LOG_TAG, \
155 (_fmt), ##__VA_ARGS__); \
156 } \
157 } while (0)
158
159#define BT_LIB_LOGF(_fmt, ...) BT_LIB_LOG(BT_LOG_FATAL, _fmt, ##__VA_ARGS__)
160#define BT_LIB_LOGE(_fmt, ...) BT_LIB_LOG(BT_LOG_ERROR, _fmt, ##__VA_ARGS__)
161#define BT_LIB_LOGW(_fmt, ...) BT_LIB_LOG(BT_LOG_WARN, _fmt, ##__VA_ARGS__)
162#define BT_LIB_LOGI(_fmt, ...) BT_LIB_LOG(BT_LOG_INFO, _fmt, ##__VA_ARGS__)
163#define BT_LIB_LOGD(_fmt, ...) BT_LIB_LOG(BT_LOG_DEBUG, _fmt, ##__VA_ARGS__)
164#define BT_LIB_LOGV(_fmt, ...) BT_LIB_LOG(BT_LOG_VERBOSE, _fmt, ##__VA_ARGS__)
165
166/*
167 * Log statement, specialized for the Babeltrace library.
168 *
169 * Use one of the BT_LIB_LOGF*() macros above instead of calling this
170 * function directly.
171 */
172BT_HIDDEN
173void bt_lib_log(const char *func, const char *file, unsigned line,
174 int lvl, const char *tag, const char *fmt, ...);
175
beb0fb75 176#endif /* BABELTRACE_LIB_LOGGING_INTERNAL_H */
This page took 0.036374 seconds and 4 git commands to generate.