PipeWire: spa/support/log.h Source File

PipeWire 1.0.3

Loading...
Searching...
No Matches
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
36#define SPA_LOG_TOPIC_DEFAULT NULL
37
38enum spa_log_level {
39 SPA_LOG_LEVEL_NONE = 0,
40 SPA_LOG_LEVEL_ERROR,
41 SPA_LOG_LEVEL_WARN,
42 SPA_LOG_LEVEL_INFO,
43 SPA_LOG_LEVEL_DEBUG,
44 SPA_LOG_LEVEL_TRACE,
45};
46
50#define SPA_TYPE_INTERFACE_Log SPA_TYPE_INFO_INTERFACE_BASE "Log"
51
52
53struct spa_log {
56#define SPA_VERSION_LOG 0
57 struct spa_interface iface;
61 enum spa_log_level level;
62};
63
74struct spa_log_topic {
75#define SPA_VERSION_LOG_TOPIC 0
78 uint32_t version;
80 const char *topic;
82 enum spa_log_level level;
84 bool has_custom_level;
85};
86
87struct spa_log_methods {
88#define SPA_VERSION_LOG_METHODS 1
89 uint32_t version;
105 void (*log) (void *object,
106 enum spa_log_level level,
107 const char *file,
108 int line,
109 const char *func,
110 const char *fmt, ...) SPA_PRINTF_FUNC(6, 7);
111
127 void (*logv) (void *object,
128 enum spa_log_level level,
129 const char *file,
130 int line,
131 const char *func,
132 const char *fmt,
133 va_list args) SPA_PRINTF_FUNC(6, 0);
151 void (*logt) (void *object,
152 enum spa_log_level level,
153 const struct spa_log_topic *topic,
154 const char *file,
155 int line,
156 const char *func,
157 const char *fmt, ...) SPA_PRINTF_FUNC(7, 8);
158
176 void (*logtv) (void *object,
177 enum spa_log_level level,
178 const struct spa_log_topic *topic,
179 const char *file,
180 int line,
181 const char *func,
182 const char *fmt,
183 va_list args) SPA_PRINTF_FUNC(7, 0);
184
190 void (*topic_init) (void *object, struct spa_log_topic *topic);
191};
192
193
194#define SPA_LOG_TOPIC(v, t) \
195 (struct spa_log_topic){ .version = (v), .topic = (t)}
196
197static inline void spa_log_topic_init(struct spa_log *log, struct spa_log_topic *topic)
198{
199 if (SPA_UNLIKELY(!log))
200 return;
201
202 spa_interface_call(&log->iface, struct spa_log_methods, topic_init, 1, topic);
203}
204
205 static inline bool spa_log_level_topic_enabled(const struct spa_log *log,
206 const struct spa_log_topic *topic,
207 enum spa_log_level level)
208{
209 enum spa_log_level max_level;
210
211 if (SPA_UNLIKELY(!log))
212 return false;
213
214 if (topic && topic->has_custom_level)
215 max_level = topic->level;
216 else
217 max_level = log->level;
218
219 return level <= max_level;
220}
221
222/* Transparently calls to version 0 log if v1 is not supported */
223#define spa_log_logt(l,lev,topic,...) \
224({ \
225 struct spa_log *_l = l; \
226 if (SPA_UNLIKELY(spa_log_level_topic_enabled(_l, topic, lev))) { \
227 struct spa_interface *_if = &_l->iface; \
228 if (!spa_interface_call(_if, \
229 struct spa_log_methods, logt, 1, \
230 lev, topic, \
231 __VA_ARGS__)) \
232 spa_interface_call(_if, \
233 struct spa_log_methods, log, 0, \
234 lev, __VA_ARGS__); \
235 } \
236})
237
238/* Transparently calls to version 0 logv if v1 is not supported */
239#define spa_log_logtv(l,lev,topic,...) \
240({ \
241 struct spa_log *_l = l; \
242 if (SPA_UNLIKELY(spa_log_level_topic_enabled(_l, topic, lev))) { \
243 struct spa_interface *_if = &_l->iface; \
244 if (!spa_interface_call(_if, \
245 struct spa_log_methods, logtv, 1, \
246 lev, topic, \
247 __VA_ARGS__)) \
248 spa_interface_call(_if, \
249 struct spa_log_methods, logv, 0, \
250 lev, __VA_ARGS__); \
251 } \
252})
253
254#define spa_logt_lev(l,lev,t,...) \
255 spa_log_logt(l,lev,t,__FILE__,__LINE__,__func__,__VA_ARGS__)
256
257#define spa_log_lev(l,lev,...) \
258 spa_logt_lev(l,lev,SPA_LOG_TOPIC_DEFAULT,__VA_ARGS__)
259
260#define spa_log_log(l,lev,...) \
261 spa_log_logt(l,lev,SPA_LOG_TOPIC_DEFAULT,__VA_ARGS__)
262
263#define spa_log_logv(l,lev,...) \
264 spa_log_logtv(l,lev,SPA_LOG_TOPIC_DEFAULT,__VA_ARGS__)
265
266#define spa_log_error(l,...) spa_log_lev(l,SPA_LOG_LEVEL_ERROR,__VA_ARGS__)
267#define spa_log_warn(l,...) spa_log_lev(l,SPA_LOG_LEVEL_WARN,__VA_ARGS__)
268#define spa_log_info(l,...) spa_log_lev(l,SPA_LOG_LEVEL_INFO,__VA_ARGS__)
269#define spa_log_debug(l,...) spa_log_lev(l,SPA_LOG_LEVEL_DEBUG,__VA_ARGS__)
270#define spa_log_trace(l,...) spa_log_lev(l,SPA_LOG_LEVEL_TRACE,__VA_ARGS__)
271
272#define spa_logt_error(l,t,...) spa_logt_lev(l,SPA_LOG_LEVEL_ERROR,t,__VA_ARGS__)
273#define spa_logt_warn(l,t,...) spa_logt_lev(l,SPA_LOG_LEVEL_WARN,t,__VA_ARGS__)
274#define spa_logt_info(l,t,...) spa_logt_lev(l,SPA_LOG_LEVEL_INFO,t,__VA_ARGS__)
275#define spa_logt_debug(l,t,...) spa_logt_lev(l,SPA_LOG_LEVEL_DEBUG,t,__VA_ARGS__)
276#define spa_logt_trace(l,t,...) spa_logt_lev(l,SPA_LOG_LEVEL_TRACE,t,__VA_ARGS__)
277
278#ifndef FASTPATH
279#define spa_log_trace_fp(l,...) spa_log_lev(l,SPA_LOG_LEVEL_TRACE,__VA_ARGS__)
280#else
281#define spa_log_trace_fp(l,...)
282#endif
283
284
288#define SPA_KEY_LOG_LEVEL "log.level"
289#define SPA_KEY_LOG_COLORS "log.colors"
291#define SPA_KEY_LOG_FILE "log.file"
293#define SPA_KEY_LOG_TIMESTAMP "log.timestamp"
294#define SPA_KEY_LOG_LINE "log.line"
295#define SPA_KEY_LOG_PATTERNS "log.patterns"
301#ifdef __cplusplus
302} /* extern "C" */
303#endif
304#endif /* SPA_LOG_H */
defs.h
spa/utils/defs.h
spa_interface_call
#define spa_interface_call(iface, method_type, method, vers,...)
Invoke method named method in the callbacks on the given interface object.
Definition hook.h:238
spa_log_level
spa_log_level
Definition log.h:45
spa_log_topic_init
static void spa_log_topic_init(struct spa_log *log, struct spa_log_topic *topic)
Definition log.h:208
spa_log_level_topic_enabled
static 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:216
SPA_LOG_LEVEL_INFO
@ SPA_LOG_LEVEL_INFO
Definition log.h:49
SPA_LOG_LEVEL_NONE
@ SPA_LOG_LEVEL_NONE
Definition log.h:46
SPA_LOG_LEVEL_TRACE
@ SPA_LOG_LEVEL_TRACE
Definition log.h:51
SPA_LOG_LEVEL_DEBUG
@ SPA_LOG_LEVEL_DEBUG
Definition log.h:50
SPA_LOG_LEVEL_ERROR
@ SPA_LOG_LEVEL_ERROR
Definition log.h:47
SPA_LOG_LEVEL_WARN
@ SPA_LOG_LEVEL_WARN
Definition log.h:48
SPA_PRINTF_FUNC
#define SPA_PRINTF_FUNC(fmt, arg1)
Definition defs.h:277
SPA_UNLIKELY
#define SPA_UNLIKELY(x)
Definition defs.h:351
hook.h
spa/utils/hook.h
type.h
spa/utils/type.h
spa_interface
Definition hook.h:138
spa_log_methods
Definition log.h:97
spa_log_methods::version
uint32_t version
Definition log.h:100
spa_log_methods::log
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 log.h:116
spa_log_methods::logv
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 log.h:138
spa_log_methods::logt
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 log.h:162
spa_log_methods::logtv
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 log.h:187
spa_log_methods::topic_init
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 log.h:201
spa_log_topic
Identifier for a topic.
Definition log.h:83
spa_log_topic::version
uint32_t version
the version of this topic.
Definition log.h:88
spa_log_topic::has_custom_level
bool has_custom_level
False if this topic follows the Log level.
Definition log.h:94
spa_log_topic::level
enum spa_log_level level
Logging level set for this topic.
Definition log.h:92
spa_log_topic::topic
const char * topic
The string identifier for the topic.
Definition log.h:90
spa_log
Definition log.h:61
spa_log::iface
struct spa_interface iface
Definition log.h:66
spa_log::level
enum spa_log_level level
Logging level, everything above this level is not logged.
Definition log.h:70