PipeWire  0.3.66
spa/include/spa/support/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
9 extern "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 
38 enum spa_log_level {
45 };
46 
50 #define SPA_TYPE_INTERFACE_Log SPA_TYPE_INFO_INTERFACE_BASE "Log"
51 
52 
53 struct spa_log {
56 #define SPA_VERSION_LOG 0
57  struct spa_interface iface;
62 };
63 
74 struct 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 
87 struct 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 
197 #define spa_log_topic_init(l, topic) \
198 do { \
199  struct spa_log *_l = l; \
200  if (SPA_LIKELY(_l)) { \
201  struct spa_interface *_if = &_l->iface; \
202  spa_interface_call(_if, struct spa_log_methods, \
203  topic_init, 1, topic); \
204  } \
205 } while(0)
206 
207 /* Unused, left for backwards compat */
208 #define spa_log_level_enabled(l,lev) ((l) && (l)->level >= (lev))
209 
210 #define spa_log_level_topic_enabled(l,topic,lev) \
211 ({ \
212  struct spa_log *_log = l; \
213  enum spa_log_level _lev = _log ? _log->level : SPA_LOG_LEVEL_NONE; \
214  struct spa_log_topic *_t = (struct spa_log_topic *)(topic); \
215  if (_t && _t->has_custom_level) \
216  _lev = _t->level; \
217  _lev >= (lev); \
218 })
219 
220 /* Transparently calls to version 0 log if v1 is not supported */
221 #define spa_log_logt(l,lev,topic,...) \
222 ({ \
223  struct spa_log *_l = l; \
224  struct spa_interface *_if = &_l->iface; \
225  if (SPA_UNLIKELY(spa_log_level_topic_enabled(_l, topic, lev))) { \
226  if (!spa_interface_call(_if, \
227  struct spa_log_methods, logt, 1, \
228  lev, topic, \
229  __VA_ARGS__)) \
230  spa_interface_call(_if, \
231  struct spa_log_methods, log, 0, \
232  lev, __VA_ARGS__); \
233  } \
234 })
235 
236 /* Transparently calls to version 0 logv if v1 is not supported */
237 #define spa_log_logtv(l,lev,topic,...) \
238 ({ \
239  struct spa_log *_l = l; \
240  struct spa_interface *_if = &_l->iface; \
241  if (SPA_UNLIKELY(spa_log_level_topic_enabled(_l, topic, lev))) { \
242  if (!spa_interface_call(_if, \
243  struct spa_log_methods, logtv, 1, \
244  lev, topic, \
245  __VA_ARGS__)) \
246  spa_interface_call(_if, \
247  struct spa_log_methods, logv, 0, \
248  lev, __VA_ARGS__); \
249  } \
250 })
251 
252 #define spa_logt_lev(l,lev,t,...) \
253  spa_log_logt(l,lev,t,__FILE__,__LINE__,__func__,__VA_ARGS__)
254 
255 #define spa_log_lev(l,lev,...) \
256  spa_logt_lev(l,lev,SPA_LOG_TOPIC_DEFAULT,__VA_ARGS__)
257 
258 #define spa_log_log(l,lev,...) \
259  spa_log_logt(l,lev,SPA_LOG_TOPIC_DEFAULT,__VA_ARGS__)
260 
261 #define spa_log_logv(l,lev,...) \
262  spa_log_logtv(l,lev,SPA_LOG_TOPIC_DEFAULT,__VA_ARGS__)
263 
264 #define spa_log_error(l,...) spa_log_lev(l,SPA_LOG_LEVEL_ERROR,__VA_ARGS__)
265 #define spa_log_warn(l,...) spa_log_lev(l,SPA_LOG_LEVEL_WARN,__VA_ARGS__)
266 #define spa_log_info(l,...) spa_log_lev(l,SPA_LOG_LEVEL_INFO,__VA_ARGS__)
267 #define spa_log_debug(l,...) spa_log_lev(l,SPA_LOG_LEVEL_DEBUG,__VA_ARGS__)
268 #define spa_log_trace(l,...) spa_log_lev(l,SPA_LOG_LEVEL_TRACE,__VA_ARGS__)
269 
270 #define spa_logt_error(l,t,...) spa_logt_lev(l,SPA_LOG_LEVEL_ERROR,t,__VA_ARGS__)
271 #define spa_logt_warn(l,t,...) spa_logt_lev(l,SPA_LOG_LEVEL_WARN,t,__VA_ARGS__)
272 #define spa_logt_info(l,t,...) spa_logt_lev(l,SPA_LOG_LEVEL_INFO,t,__VA_ARGS__)
273 #define spa_logt_debug(l,t,...) spa_logt_lev(l,SPA_LOG_LEVEL_DEBUG,t,__VA_ARGS__)
274 #define spa_logt_trace(l,t,...) spa_logt_lev(l,SPA_LOG_LEVEL_TRACE,t,__VA_ARGS__)
275 
276 #ifndef FASTPATH
277 #define spa_log_trace_fp(l,...) spa_log_lev(l,SPA_LOG_LEVEL_TRACE,__VA_ARGS__)
278 #else
279 #define spa_log_trace_fp(l,...)
280 #endif
281 
282 
286 #define SPA_KEY_LOG_LEVEL "log.level"
287 #define SPA_KEY_LOG_COLORS "log.colors"
288 #define SPA_KEY_LOG_FILE "log.file"
290 #define SPA_KEY_LOG_TIMESTAMP "log.timestamp"
291 #define SPA_KEY_LOG_LINE "log.line"
292 #define SPA_KEY_LOG_PATTERNS "log.patterns"
298 #ifdef __cplusplus
299 } /* extern "C" */
300 #endif
301 #endif /* SPA_LOG_H */
spa/utils/defs.h
spa_log_level
Definition: spa/include/spa/support/log.h:45
@ SPA_LOG_LEVEL_INFO
Definition: spa/include/spa/support/log.h:49
@ SPA_LOG_LEVEL_NONE
Definition: spa/include/spa/support/log.h:46
@ SPA_LOG_LEVEL_TRACE
Definition: spa/include/spa/support/log.h:51
@ SPA_LOG_LEVEL_DEBUG
Definition: spa/include/spa/support/log.h:50
@ SPA_LOG_LEVEL_ERROR
Definition: spa/include/spa/support/log.h:47
@ SPA_LOG_LEVEL_WARN
Definition: spa/include/spa/support/log.h:48
#define SPA_PRINTF_FUNC(fmt, arg1)
Definition: defs.h:273
spa/utils/hook.h
spa/utils/type.h
Definition: hook.h:138
Definition: spa/include/spa/support/log.h:97
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: spa/include/spa/support/log.h:162
uint32_t version
Definition: spa/include/spa/support/log.h:100
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: spa/include/spa/support/log.h:201
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: spa/include/spa/support/log.h:138
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: spa/include/spa/support/log.h:116
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: spa/include/spa/support/log.h:187
Identifier for a topic.
Definition: spa/include/spa/support/log.h:83
uint32_t version
the version of this topic.
Definition: spa/include/spa/support/log.h:88
bool has_custom_level
False if this topic follows the Log level.
Definition: spa/include/spa/support/log.h:94
enum spa_log_level level
Logging level set for this topic.
Definition: spa/include/spa/support/log.h:92
const char * topic
The string identifier for the topic.
Definition: spa/include/spa/support/log.h:90
Definition: spa/include/spa/support/log.h:61
struct spa_interface iface
Definition: spa/include/spa/support/log.h:66
enum spa_log_level level
Logging level, everything above this level is not logged.
Definition: spa/include/spa/support/log.h:70