PipeWire 0.3.38
x86_64-FusionOS-linux-gnu/doc/spa/support/log.h
Go to the documentation of this file.
1/* Simple Plugin API
2 *
3 * Copyright © 2018 Wim Taymans
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
14 * Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 */
24
25#ifndef SPA_LOG_H
26#define SPA_LOG_H
27
28#ifdef __cplusplus
29extern "C" {
30#endif
31
32#include <stdarg.h>
33
34#include <spa/utils/type.h>
35#include <spa/utils/defs.h>
36#include <spa/utils/hook.h>
37
55#define SPA_LOG_TOPIC_DEFAULT NULL
56
64};
65
69#define SPA_TYPE_INTERFACE_Log SPA_TYPE_INFO_INTERFACE_BASE "Log"
70
71
72struct spa_log {
75#define SPA_VERSION_LOG 0
81};
82
94#define SPA_VERSION_LOG_TOPIC 0
97 uint32_t version;
99 const char *topic;
104};
105
107#define SPA_VERSION_LOG_METHODS 1
108 uint32_t version;
124 void (*log) (void *object,
125 enum spa_log_level level,
126 const char *file,
127 int line,
128 const char *func,
129 const char *fmt, ...) SPA_PRINTF_FUNC(6, 7);
130
146 void (*logv) (void *object,
147 enum spa_log_level level,
148 const char *file,
149 int line,
150 const char *func,
151 const char *fmt,
152 va_list args) SPA_PRINTF_FUNC(6, 0);
170 void (*logt) (void *object,
171 enum spa_log_level level,
172 const struct spa_log_topic *topic,
173 const char *file,
174 int line,
175 const char *func,
176 const char *fmt, ...) SPA_PRINTF_FUNC(7, 8);
177
195 void (*logtv) (void *object,
196 enum spa_log_level level,
197 const struct spa_log_topic *topic,
198 const char *file,
199 int line,
200 const char *func,
201 const char *fmt,
202 va_list args) SPA_PRINTF_FUNC(7, 0);
203
209 void (*topic_init) (void *object, struct spa_log_topic *topic);
210};
211
212
213#define SPA_LOG_TOPIC(v, t) \
214 (struct spa_log_topic){ .version = v, .topic = (t)}
215
216#define spa_log_topic_init(l, topic) \
217do { \
218 struct spa_log *_l = l; \
219 if (SPA_LIKELY(_l)) { \
220 struct spa_interface *_if = &_l->iface; \
221 spa_interface_call(_if, struct spa_log_methods, \
222 topic_init, 1, topic); \
223 } \
224} while(0)
225
226/* Unused, left for backwards compat */
227#define spa_log_level_enabled(l,lev) ((l) && (l)->level >= (lev))
228
229#define spa_log_level_topic_enabled(l,topic,lev) \
230({ \
231 struct spa_log *_log = l; \
232 enum spa_log_level _lev = _log ? _log->level : SPA_LOG_LEVEL_NONE; \
233 struct spa_log_topic *_t = (struct spa_log_topic *)topic; \
234 if (_t && _t->has_custom_level) \
235 _lev = _t->level; \
236 _lev >= lev; \
237})
238
239/* Transparently calls to version 0 log if v1 is not supported */
240#define spa_log_logt(l,lev,topic,...) \
241({ \
242 struct spa_log *_l = l; \
243 struct spa_interface *_if = &_l->iface; \
244 if (SPA_UNLIKELY(spa_log_level_topic_enabled(_l, topic, lev))) { \
245 if (spa_interface_callback_version_min( \
246 _if, struct spa_log_methods, 1)) \
247 spa_interface_call(_if, \
248 struct spa_log_methods, logt, 1, \
249 lev, topic, \
250 __VA_ARGS__); \
251 else \
252 spa_interface_call(_if, \
253 struct spa_log_methods, log, 0, \
254 lev, __VA_ARGS__); \
255 } \
256})
257
258/* Transparently calls to version 0 logv if v1 is not supported */
259#define spa_log_logtv(l,lev,topic,...) \
260({ \
261 struct spa_log *_l = l; \
262 struct spa_interface *_if = &_l->iface; \
263 if (SPA_UNLIKELY(spa_log_level_topic_enabled(_l, topic, lev))) { \
264 if (spa_interface_callback_version_min( \
265 _if, struct spa_log_methods, 1)) \
266 spa_interface_call(_if, \
267 struct spa_log_methods, logtv, 1, \
268 lev, topic, \
269 __VA_ARGS__); \
270 else \
271 spa_interface_call(_if, \
272 struct spa_log_methods, logv, 0, \
273 lev, __VA_ARGS__); \
274 } \
275})
276
277#define spa_log_log(l,lev,...) \
278 spa_log_logt(l,lev,SPA_LOG_TOPIC_DEFAULT,__VA_ARGS__)
279
280#define spa_log_logv(l,lev,...) \
281 spa_log_logtv(l,lev,SPA_LOG_TOPIC_DEFAULT,__VA_ARGS__)
282
283#define spa_log_error(l,...) spa_log_log(l,SPA_LOG_LEVEL_ERROR,__FILE__,__LINE__,__func__,__VA_ARGS__)
284#define spa_log_warn(l,...) spa_log_log(l,SPA_LOG_LEVEL_WARN,__FILE__,__LINE__,__func__,__VA_ARGS__)
285#define spa_log_info(l,...) spa_log_log(l,SPA_LOG_LEVEL_INFO,__FILE__,__LINE__,__func__,__VA_ARGS__)
286#define spa_log_debug(l,...) spa_log_log(l,SPA_LOG_LEVEL_DEBUG,__FILE__,__LINE__,__func__,__VA_ARGS__)
287#define spa_log_trace(l,...) spa_log_log(l,SPA_LOG_LEVEL_TRACE,__FILE__,__LINE__,__func__,__VA_ARGS__)
288
289#define spa_logt_error(l,t,...) spa_log_logt(l,SPA_LOG_LEVEL_ERROR,t,__FILE__,__LINE__,__func__,__VA_ARGS__)
290#define spa_logt_warn(l,t,...) spa_log_logt(l,SPA_LOG_LEVEL_WARN,t,__FILE__,__LINE__,__func__,__VA_ARGS__)
291#define spa_logt_info(l,t,...) spa_log_logt(l,SPA_LOG_LEVEL_INFO,t,__FILE__,__LINE__,__func__,__VA_ARGS__)
292#define spa_logt_debug(l,t,...) spa_log_logt(l,SPA_LOG_LEVEL_DEBUG,t,__FILE__,__LINE__,__func__,__VA_ARGS__)
293#define spa_logt_trace(l,t,...) spa_log_logt(l,SPA_LOG_LEVEL_TRACE,t,__FILE__,__LINE__,__func__,__VA_ARGS__)
294
295#ifndef FASTPATH
296#define spa_log_trace_fp(l,...) spa_log_log(l,SPA_LOG_LEVEL_TRACE,__FILE__,__LINE__,__func__,__VA_ARGS__)
297#else
298#define spa_log_trace_fp(l,...)
299#endif
300
304#define SPA_KEY_LOG_LEVEL "log.level"
305#define SPA_KEY_LOG_COLORS "log.colors"
306#define SPA_KEY_LOG_FILE "log.file"
308#define SPA_KEY_LOG_TIMESTAMP "log.timestamp"
309#define SPA_KEY_LOG_LINE "log.line"
310#define SPA_KEY_LOG_PATTERNS "log.patterns"
316#ifdef __cplusplus
317} /* extern "C" */
318#endif
319#endif /* SPA_LOG_H */
spa_log_level
Definition: x86_64-FusionOS-linux-gnu/doc/spa/support/log.h:57
@ SPA_LOG_LEVEL_INFO
Definition: x86_64-FusionOS-linux-gnu/doc/spa/support/log.h:61
@ SPA_LOG_LEVEL_NONE
Definition: x86_64-FusionOS-linux-gnu/doc/spa/support/log.h:58
@ SPA_LOG_LEVEL_TRACE
Definition: x86_64-FusionOS-linux-gnu/doc/spa/support/log.h:63
@ SPA_LOG_LEVEL_DEBUG
Definition: x86_64-FusionOS-linux-gnu/doc/spa/support/log.h:62
@ SPA_LOG_LEVEL_ERROR
Definition: x86_64-FusionOS-linux-gnu/doc/spa/support/log.h:59
@ SPA_LOG_LEVEL_WARN
Definition: x86_64-FusionOS-linux-gnu/doc/spa/support/log.h:60
#define SPA_PRINTF_FUNC(fmt, arg1)
Definition: defs.h:211
Definition: hook.h:149
Definition: x86_64-FusionOS-linux-gnu/doc/spa/support/log.h:106
void(*) void(*) void(* logt)(void *object, enum spa_log_level level, const struct spa_log_topic *topic, const char *file, int line, const char *func, const char *fmt,...) 1(7
Log a message with the given log level for the given topic.
Definition: x86_64-FusionOS-linux-gnu/doc/spa/support/log.h:170
uint32_t version
Definition: x86_64-FusionOS-linux-gnu/doc/spa/support/log.h:108
void(*) void(*) void(*) void(*) void(* topic_init)(void *object, struct spa_log_topic *topic)
Initializes a spa_log_topic to the correct logging level.
Definition: x86_64-FusionOS-linux-gnu/doc/spa/support/log.h:209
void(*) void(* logv)(void *object, enum spa_log_level level, const char *file, int line, const char *func, const char *fmt, va_list args) 1(6
Log a message with the given log level.
Definition: x86_64-FusionOS-linux-gnu/doc/spa/support/log.h:146
void(* log)(void *object, enum spa_log_level level, const char *file, int line, const char *func, const char *fmt,...) 1(6
Log a message with the given log level.
Definition: x86_64-FusionOS-linux-gnu/doc/spa/support/log.h:124
void(*) void(*) void(*) void(* logtv)(void *object, enum spa_log_level level, const struct spa_log_topic *topic, const char *file, int line, const char *func, const char *fmt, va_list args) 1(7
Log a message with the given log level for the given topic.
Definition: x86_64-FusionOS-linux-gnu/doc/spa/support/log.h:195
Identifier for a topic.
Definition: x86_64-FusionOS-linux-gnu/doc/spa/support/log.h:93
uint32_t version
the version of this topic.
Definition: x86_64-FusionOS-linux-gnu/doc/spa/support/log.h:97
bool has_custom_level
False if this topic follows the SPA Logging level.
Definition: x86_64-FusionOS-linux-gnu/doc/spa/support/log.h:103
enum spa_log_level level
Logging level set for this topic.
Definition: x86_64-FusionOS-linux-gnu/doc/spa/support/log.h:101
const char * topic
The string identifier for the topic.
Definition: x86_64-FusionOS-linux-gnu/doc/spa/support/log.h:99
Definition: x86_64-FusionOS-linux-gnu/doc/spa/support/log.h:72
struct spa_interface iface
Definition: x86_64-FusionOS-linux-gnu/doc/spa/support/log.h:76
enum spa_log_level level
Logging level, everything above this level is not logged.
Definition: x86_64-FusionOS-linux-gnu/doc/spa/support/log.h:80