PipeWire 1.4.1
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
log.h
Go to the documentation of this file.
1/* Simple Plugin API */
2/* SPDX-FileCopyrightText: Copyright © 2018 Wim Taymans */
3/* SPDX-License-Identifier: MIT */
4
5#ifndef SPA_LOG_H
6#define SPA_LOG_H
7
8#ifdef __cplusplus
9extern "C" {
10#endif
11
12#include <stdarg.h>
13
14#include <spa/utils/type.h>
15#include <spa/utils/defs.h>
16#include <spa/utils/hook.h>
17
18#ifndef SPA_API_LOG
19 #ifdef SPA_API_IMPL
20 #define SPA_API_LOG SPA_API_IMPL
21 #else
22 #define SPA_API_LOG static inline
23 #endif
24#endif
25
44#define SPA_LOG_TOPIC_DEFAULT NULL
45
46enum spa_log_level {
53};
54
58#define SPA_TYPE_INTERFACE_Log SPA_TYPE_INFO_INTERFACE_BASE "Log"
61struct spa_log {
64#define SPA_VERSION_LOG 0
65 struct spa_interface iface;
70};
82struct spa_log_topic {
83#define SPA_VERSION_LOG_TOPIC 0
86 uint32_t version;
88 const char *topic;
93};
94
101#define SPA_VERSION_LOG_TOPIC_ENUM 0
102 uint32_t version;
104 struct spa_log_topic * const * const topics;
106 struct spa_log_topic * const * const topics_end;
107};
108
109
110struct spa_log_methods {
111#define SPA_VERSION_LOG_METHODS 1
112 uint32_t version;
128 void (*log) (void *object,
129 enum spa_log_level level,
130 const char *file,
131 int line,
132 const char *func,
133 const char *fmt, ...) SPA_PRINTF_FUNC(6, 7);
134
150 void (*logv) (void *object,
151 enum spa_log_level level,
152 const char *file,
153 int line,
154 const char *func,
155 const char *fmt,
156 va_list args) SPA_PRINTF_FUNC(6, 0);
174 void (*logt) (void *object,
175 enum spa_log_level level,
176 const struct spa_log_topic *topic,
177 const char *file,
178 int line,
179 const char *func,
180 const char *fmt, ...) SPA_PRINTF_FUNC(7, 8);
181
199 void (*logtv) (void *object,
200 enum spa_log_level level,
201 const struct spa_log_topic *topic,
202 const char *file,
203 int line,
204 const char *func,
205 const char *fmt,
206 va_list args) SPA_PRINTF_FUNC(7, 0);
207
217 void (*topic_init) (void *object, struct spa_log_topic *topic);
218};
219
220
221#define SPA_LOG_TOPIC(v, t) \
222 (struct spa_log_topic){ .version = (v), .topic = (t)}
223
224SPA_API_LOG void spa_log_topic_init(struct spa_log *log, struct spa_log_topic *topic)
225{
226 if (SPA_UNLIKELY(!log))
227 return;
228
229 spa_interface_call(&log->iface, struct spa_log_methods, topic_init, 1, topic);
230}
232SPA_API_LOG bool spa_log_level_topic_enabled(const struct spa_log *log,
233 const struct spa_log_topic *topic,
234 enum spa_log_level level)
236 enum spa_log_level max_level;
237
238 if (SPA_UNLIKELY(!log))
239 return false;
240
241 if (topic && topic->has_custom_level)
242 max_level = topic->level;
243 else
244 max_level = log->level;
245
246 return level <= max_level;
247}
248
249/* Transparently calls to version 0 log if v1 is not supported */
250#define spa_log_logt(l,lev,topic,...) \
251({ \
252 struct spa_log *_l = l; \
253 if (SPA_UNLIKELY(spa_log_level_topic_enabled(_l, topic, lev))) { \
254 struct spa_interface *_if = &_l->iface; \
255 if (!spa_interface_call(_if, \
256 struct spa_log_methods, logt, 1, \
257 lev, topic, \
258 __VA_ARGS__)) \
259 spa_interface_call(_if, \
260 struct spa_log_methods, log, 0, \
261 lev, __VA_ARGS__); \
262 } \
263})
265/* Transparently calls to version 0 logv if v1 is not supported */
266SPA_PRINTF_FUNC(7, 0)
268 const struct spa_log_topic *topic, const char *file, int line,
269 const char *func, const char *fmt, va_list args)
270{
272 struct spa_interface *i = &l->iface;
273 if (!spa_interface_call(i,
274 struct spa_log_methods, logtv, 1,
275 level, topic,
276 file, line, func, fmt, args))
278 struct spa_log_methods, logv, 0,
279 level, file, line, func, fmt, args);
280 }
282
283#define spa_logt_lev(l,lev,t,...) \
284 spa_log_logt(l,lev,t,__FILE__,__LINE__,__func__,__VA_ARGS__)
285
286#define spa_log_lev(l,lev,...) \
287 spa_logt_lev(l,lev,SPA_LOG_TOPIC_DEFAULT,__VA_ARGS__)
288
289#define spa_log_log(l,lev,...) \
290 spa_log_logt(l,lev,SPA_LOG_TOPIC_DEFAULT,__VA_ARGS__)
291
292#define spa_log_logv(l,lev,...) \
293 spa_log_logtv(l,lev,SPA_LOG_TOPIC_DEFAULT,__VA_ARGS__)
294
295#define spa_log_error(l,...) spa_log_lev(l,SPA_LOG_LEVEL_ERROR,__VA_ARGS__)
296#define spa_log_warn(l,...) spa_log_lev(l,SPA_LOG_LEVEL_WARN,__VA_ARGS__)
297#define spa_log_info(l,...) spa_log_lev(l,SPA_LOG_LEVEL_INFO,__VA_ARGS__)
298#define spa_log_debug(l,...) spa_log_lev(l,SPA_LOG_LEVEL_DEBUG,__VA_ARGS__)
299#define spa_log_trace(l,...) spa_log_lev(l,SPA_LOG_LEVEL_TRACE,__VA_ARGS__)
301#define spa_logt_error(l,t,...) spa_logt_lev(l,SPA_LOG_LEVEL_ERROR,t,__VA_ARGS__)
302#define spa_logt_warn(l,t,...) spa_logt_lev(l,SPA_LOG_LEVEL_WARN,t,__VA_ARGS__)
303#define spa_logt_info(l,t,...) spa_logt_lev(l,SPA_LOG_LEVEL_INFO,t,__VA_ARGS__)
304#define spa_logt_debug(l,t,...) spa_logt_lev(l,SPA_LOG_LEVEL_DEBUG,t,__VA_ARGS__)
305#define spa_logt_trace(l,t,...) spa_logt_lev(l,SPA_LOG_LEVEL_TRACE,t,__VA_ARGS__)
307#ifndef FASTPATH
308#define spa_log_trace_fp(l,...) spa_log_lev(l,SPA_LOG_LEVEL_TRACE,__VA_ARGS__)
309#else
310#define spa_log_trace_fp(l,...)
311#endif
320#define SPA_LOG_TOPIC_ENUM_NAME "spa_log_topic_enum"
321
327#define SPA_LOG_TOPIC_ENUM_DEFINE(s, e) \
328 SPA_EXPORT struct spa_log_topic_enum spa_log_topic_enum = (struct spa_log_topic_enum) { \
329 .version = SPA_VERSION_LOG_TOPIC_ENUM, \
330 .topics = (s), \
331 .topics_end = (e), \
332 }
333
340#define SPA_LOG_TOPIC_REGISTER(v) \
341 __attribute__((used)) __attribute__((retain)) \
342 __attribute__((section("spa_log_topic"))) __attribute__((aligned(__alignof__(struct spa_log_topic *)))) \
343 static struct spa_log_topic * const spa_log_topic_export_##v = &v
344
350#define SPA_LOG_TOPIC_DEFINE(var,name) \
351 struct spa_log_topic var = SPA_LOG_TOPIC(SPA_VERSION_LOG_TOPIC, name); \
352 SPA_LOG_TOPIC_REGISTER(var)
353
359#define SPA_LOG_TOPIC_DEFINE_STATIC(var,name) \
360 static struct spa_log_topic var = SPA_LOG_TOPIC(SPA_VERSION_LOG_TOPIC, name); \
361 SPA_LOG_TOPIC_REGISTER(var)
362
369#define SPA_LOG_TOPIC_ENUM_DEFINE_REGISTERED \
370 extern struct spa_log_topic * const __start_spa_log_topic[]; \
371 extern struct spa_log_topic * const __stop_spa_log_topic[]; \
372 SPA_LOG_TOPIC_ENUM_DEFINE(__start_spa_log_topic, __stop_spa_log_topic)
373
377#define SPA_KEY_LOG_LEVEL "log.level"
378#define SPA_KEY_LOG_COLORS "log.colors"
380#define SPA_KEY_LOG_FILE "log.file"
382#define SPA_KEY_LOG_TIMESTAMP "log.timestamp"
384#define SPA_KEY_LOG_LINE "log.line"
385#define SPA_KEY_LOG_PATTERNS "log.patterns"
391#ifdef __cplusplus
392} /* extern "C" */
393#endif
394#endif /* SPA_LOG_H */
spa/utils/defs.h
uint32_t int int const char va_list args
Definition core.h:434
#define spa_interface_call(iface, method_type, method, vers,...)
Invoke method named method in the callbacks on the given interface object.
Definition hook.h:248
spa_log_level
Definition log.h:55
SPA_API_LOG bool spa_log_level_topic_enabled(const struct spa_log *log, const struct spa_log_topic *topic, enum spa_log_level level)
Definition log.h:246
SPA_API_LOG void spa_log_topic_init(struct spa_log *log, struct spa_log_topic *topic)
Definition log.h:238
SPA_API_LOG void spa_log_logtv(struct spa_log *l, 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)
Definition log.h:281
@ SPA_LOG_LEVEL_INFO
Definition log.h:59
@ SPA_LOG_LEVEL_NONE
Definition log.h:56
@ SPA_LOG_LEVEL_TRACE
Definition log.h:61
@ SPA_LOG_LEVEL_DEBUG
Definition log.h:60
@ SPA_LOG_LEVEL_ERROR
Definition log.h:57
@ SPA_LOG_LEVEL_WARN
Definition log.h:58
#define SPA_PRINTF_FUNC(fmt, arg1)
Definition defs.h:295
#define SPA_UNLIKELY(x)
Definition defs.h:394
spa/utils/hook.h
#define SPA_API_LOG
Definition log.h:29
spa/utils/type.h
Definition hook.h:148
Definition log.h:123
void(* logv)(void *object, enum spa_log_level level, const char *file, int line, const char *func, const char *fmt, va_list args)
Log a message with the given log level.
Definition log.h:164
uint32_t version
Definition log.h:126
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)
Log a message with the given log level for the given topic.
Definition log.h:213
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,...)
Log a message with the given log level for the given topic.
Definition log.h:188
void(* topic_init)(void *object, struct spa_log_topic *topic)
Initializes a spa_log_topic to the correct logging level.
Definition log.h:231
void(* log)(void *object, enum spa_log_level level, const char *file, int line, const char *func, const char *fmt,...)
Log a message with the given log level.
Definition log.h:142
Enumeration of log topics in a plugin.
Definition log.h:112
struct spa_log_topic *const *const topics_end
End of topics array.
Definition log.h:119
struct spa_log_topic *const *const topics
Array of pointers to log topics.
Definition log.h:117
uint32_t version
Definition log.h:115
Identifier for a topic.
Definition log.h:93
uint32_t version
the version of this topic.
Definition log.h:98
bool has_custom_level
False if this topic follows the Log level.
Definition log.h:104
enum spa_log_level level
Logging level set for this topic.
Definition log.h:102
const char * topic
The string identifier for the topic.
Definition log.h:100
Definition log.h:71
struct spa_interface iface
Definition log.h:76
enum spa_log_level level
Logging level, everything above this level is not logged.
Definition log.h:80